Questions tagged [portability]

Portable code can be run with little to no modification in multiple environments. Portable applications can be run from e.g. a USB drive without modifying a computer's environment.

Filter by
Sorted by
Tagged with
1094 votes
16 answers
416k views

What is the meaning of "POSIX"?

What exactly is POSIX? I have read the Wikipedia article but I still don't understand.
claws's user avatar
  • 53.3k
863 votes
2 answers
374k views

How do SO_REUSEADDR and SO_REUSEPORT differ?

The man pages and programmer documentations for the socket options SO_REUSEADDR and SO_REUSEPORT are different for different operating systems and often highly confusing. Some operating systems don't ...
Mecki's user avatar
  • 130k
768 votes
15 answers
576k views

Is there a portable way to get the current username in Python?

What is a portable way (e.g. for Linux and Windows) to get the current user's username? Something similar to os.getuid() would be nice: >>> os.getuid() 42 # Does not currently exist in ...
Jacob Gabrielson's user avatar
462 votes
10 answers
93k views

Why should I not #include <bits/stdc++.h>?

I posted a question with my code whose only #include directive was the following: #include <bits/stdc++.h> My teacher told me to do this, but in the comments section I was informed that I ...
Lightness Races in Orbit's user avatar
306 votes
9 answers
65k views

Why does glibc's strlen need to be so complicated to run quickly?

I was looking through the strlen code here and I was wondering if the optimizations used in the code are really needed? For example, why wouldn't something like the following work equally good or ...
user avatar
223 votes
10 answers
427k views

Is there a replacement for unistd.h for Windows (Visual C)?

I'm porting a relatively simple console program written for Unix to the Windows platform (Visual C++ 8.0). All the source files include "unistd.h", which doesn't exist. Removing it, I get ...
AShelly's user avatar
  • 35k
181 votes
10 answers
207k views

OS specific instructions in CMAKE: How to?

I am a beginner to CMAKE. Below is a simple cmake file which works well in mingw environment windows. The problem is clearly with target_link_libraries() function of CMAKE where I am linking ...
Prasad's user avatar
  • 1,961
177 votes
7 answers
117k views

How can I mark a C++ class method as deprecated?

I have a method in a C++ interface that I want to deprecate, with portable code. When I Googled for this all I got was a Microsoft specific solution; #pragma deprecated and __declspec(deprecated). If ...
Diederik's user avatar
  • 6,070
160 votes
10 answers
160k views

How should I print types like off_t and size_t?

I'm trying to print types like off_t and size_t. What is the correct placeholder for printf() that is portable? Or is there a completely different way to print those variables?
Georg Schölly's user avatar
158 votes
9 answers
270k views

How to measure time in milliseconds using ANSI C?

Using only ANSI C, is there any way to measure time with milliseconds precision or more? I was browsing time.h but I only found second precision functions.
corto's user avatar
  • 2,677
125 votes
23 answers
10k views

What belongs in an educational tool to demonstrate the unwarranted assumptions people make in C/C++?

I'd like to prepare a little educational tool for SO which should help beginners (and intermediate) programmers to recognize and challenge their unwarranted assumptions in C, C++ and their platforms. ...
93 votes
7 answers
115k views

How to bundle a JRE with Launch4j?

I have Launch4J on my computer and it's a great program. One of its features I'm interested in is the ability to bundle a JRE in the general .EXE file. However, I can't find any documentation that ...
CodeBunny's user avatar
  • 1,991
92 votes
4 answers
14k views

Are the experimental features of modern C++ reliable for long-term projects?

I have a project that currently uses C++11/14, but it requires something like std::filesystem, which is only available in C++17, and hence I don't have a chance to currently use it. I see, however, ...
The Quantum Physicist's user avatar
91 votes
9 answers
6k views

How can I portably call a C++ function that takes a char** on some platforms and a const char** on others?

On my Linux (and OS X) machines, the iconv() function has this prototype: size_t iconv (iconv_t, char **inbuf... while on FreeBSD it looks like this: size_t iconv (iconv_t, const char **inbuf... I ...
ridiculous_fish's user avatar
89 votes
11 answers
65k views

Is there a portable equivalent to DebugBreak()/__debugbreak?

In MSVC, DebugBreak() or __debugbreak cause a debugger to break. On x86 it is equivalent to writing "_asm int 3", on x64 it is something different. When compiling with gcc (or any other standard ...
vividos's user avatar
  • 6,598
86 votes
10 answers
135k views

How to Declare a 32-bit Integer in C

What's the best way to declare an integer type which is always 4 byte on any platforms? I don't worry about certain device or old machines which has 16-bit int.
ZZ Coder's user avatar
  • 75.1k
86 votes
4 answers
73k views

Is char *envp[] as a third argument to main() portable [duplicate]

In order to get an environment variable in a C program, one could use the following: getenv() extern char **environ; But other than the above mentioned, is using char *envp[] as a third argument ...
Sangeeth Saravanaraj's user avatar
83 votes
6 answers
87k views

Portable way of setting std::thread priority in C++11

What is the correct way in the post C++11 world for setting the priority of an instance of std::thread Is there a portable way of doing this that works at least in Windows and POSIX (Linux) ...
Gerdiner's user avatar
  • 1,465
80 votes
17 answers
71k views

Django: 'current_tags' is not a valid tag library

I have a small Django project I received from a friend. The code works perfectly on his system. However, on my system I get the following error message when running the server: TemplateSyntaxError at ...
snakile's user avatar
  • 53.8k
79 votes
4 answers
60k views

How do I type a floating point infinity literal in python

How do I type a floating point infinity literal in python? I have heard inf = float('inf') is non portable. Thus, I have had the following recommended: inf = 1e400 Is either of these standard,...
fmark's user avatar
  • 57.9k
78 votes
8 answers
50k views

Why bit endianness is an issue in bitfields?

Any portable code that uses bitfields seems to distinguish between little- and big-endian platforms. See the declaration of struct iphdr in linux kernel for an example of such code. I fail to ...
Leonid99's user avatar
  • 1,267
77 votes
8 answers
56k views

Is there any "standard" htonl-like function for 64 bits integers in C++?

I'm working on an implementation of the memcache protocol which, at some points, uses 64 bits integer values. These values must be stored in "network byte order". I wish there was some uint64_t ...
ereOn's user avatar
  • 54.8k
76 votes
7 answers
155k views

Using Python's ftplib to get a directory listing, portably

You can use ftplib for full FTP support in Python. However the preferred way of getting a directory listing is: # File: ftplib-example-1.py import ftplib ftp = ftplib.FTP("www.python.org") ftp....
andrewrk's user avatar
  • 30.7k
69 votes
1 answer
53k views

Proper shebang for Python script

I'm usually using the following shebang declaration in my Python scripts: #!/usr/bin/python Recently, I've came across this shebang declaration: #!/usr/bin/env python In the script documentation, ...
Adam Matan's user avatar
  • 133k
67 votes
3 answers
26k views

how portable is end iterator decrement?

Just encountered decrement of end() iterator in my company source codes and it looks strange for me. As far as I remember this was working on some platforms, but not for the others. Maybe I'm wrong, ...
ledokol's user avatar
  • 673
65 votes
6 answers
49k views

Portability of #warning preprocessor directive

I know that the #warning directive is not standard C/C++, but several compilers support it, including gcc/g++. But for those that don't support it, will they silently ignore it or will it result in a ...
jonner's user avatar
  • 6,451
63 votes
9 answers
118k views

Change the current working directory in C++

How can I change my current working directory in C++ in a platform-agnostic way? I found the direct.h header file, which is Windows compatible, and the unistd.h, which is UNIX/POSIX compatible.
sparkFinder's user avatar
  • 3,374
60 votes
6 answers
150k views

Multi-character constant warnings

Why is this a warning? I think there are many cases when is more clear to use multi-char int constants instead of "no meaning" numbers or instead of defining const variables with same value. When ...
Mircea Ispas's user avatar
  • 20.6k
56 votes
8 answers
58k views

Checking the gcc version in a Makefile?

I would like to use some gcc warning switchs that aren't available in older gcc versions (eg. -Wtype-limits). Is there an easy way to check the gcc version and only add those extra options if a ...
Gene Vincent's user avatar
  • 5,309
56 votes
4 answers
13k views

How do I detect if I'm running MATLAB or Octave?

I need to write code that should run equally well in Octave and on MATLAB. Problem is that it needs to do some GUI stuff, which MATLAB and Octave handle completely differently. Is there a way I can ...
lindelof's user avatar
  • 35k
53 votes
3 answers
17k views

Is there any guidance on converting existing .NET class libraries to portable libraries?

I have some class libraries with a non-trivial amount of existing code. The class libraries currently target .NET 4.0. Is there any guidance on how to convert these libraries to be portable libraries? ...
Mark Stafford - MSFT's user avatar
49 votes
4 answers
45k views

When is the use of std::ref necessary? [duplicate]

Consider: std::tuple<int , const A&> func (const A& a) { return std::make_tuple( 0 , std::ref(a) ); } Is the std::ref required for writing correct and portable code? (It compiles ...
ritter's user avatar
  • 7,639
49 votes
8 answers
18k views

Can placement new for arrays be used in a portable way?

Is it possible to actually make use of placement new in portable code when using it for arrays? It appears that the pointer you get back from new[] is not always the same as the address you pass in (...
James Sutherland's user avatar
48 votes
4 answers
39k views

What is the most portable/cross-platform way to represent a newline in go/golang?

Currently, to represent a newline in go programs, I use \n. For example: package main import "fmt" func main() { fmt.Printf("%d is %s \n", 'U', string(85)) } ... will yield 85 is U followed by ...
carbocation's user avatar
  • 9,168
47 votes
9 answers
13k views

Portability of binary serialization of double/float type in C++

The C++ standard does not discuss the underlying layout of float and double types, only the range of values they should represent. (This is also true for signed types, is it two's compliment or ...
user avatar
46 votes
7 answers
8k views

How to design a C / C++ library to be usable in many client languages? [closed]

I'm planning to code a library that should be usable by a large number of people in on a wide spectrum of platforms. What do I have to consider to design it right? To make this questions more specific,...
Lena Schimmel's user avatar
45 votes
2 answers
24k views

Autotools vs CMake for both Windows and Linux compilation

I have been looking for pros & cons of Autotools and CMake. But I would like to know opinions from people having used one (or both) of these tools for projects. I used Autotools very basically a ...
Julio Guerra's user avatar
  • 5,613
44 votes
9 answers
29k views

msys path conversion (or cygpath for msys?)

I need to pass /DEF:c:\filepath\myLib.def" command line option from a bash script to MS compiler/linker. The path is generated as part of build process by a bash script. Basically, the argument that ...
Pavel P's user avatar
  • 16.3k
44 votes
7 answers
14k views

What's the difference between "int" and "int_fast16_t"?

As I understand it, the C specification says that type int is supposed to be the most efficient type on target platform that contains at least 16 bits. Isn't that exactly what the C99 definition of ...
something_clever's user avatar
41 votes
3 answers
6k views

C++: Is there a standard definition for end-of-line in a multi-line string constant?

If I have a multi-line string C++11 string constant such as R"""line 1 line 2 line3""" Is it defined what character(s) the line terminator/separator consist of?
Mark Harrison's user avatar
41 votes
3 answers
51k views

GLIBCXX versions

If I compile a C++ program on my machine, and run it on another one (with older software) I get: /usr/lib/libstdc++.so.6: version `GLIBCXX_3.4.9' not found. In fact on my system glibc is newer (I got ...
peoro's user avatar
  • 25.8k
40 votes
2 answers
11k views

What is the difference between a wrapper, a binding, and a port?

In a software portability context, what is the difference between these three concepts? For example, I want to use the ncurses library, the original ncurses library is written in C, but my ...
user478249's user avatar
40 votes
8 answers
34k views

A step-up from TiddlyWiki that is still 100% portable?

TiddlyWiki is a great idea, brilliantly implemented. I'm using it as a portable personal "knowledge manager," and these are the prize virtues: It travels on my USB flash memory stick and runs on any ...
Smandoli's user avatar
  • 6,931
40 votes
2 answers
23k views

What is the smallest possible Windows (PE) executable?

As a precursor to writing a compiler I'm trying to understand the Windows (32-bit) Portable Executable format. In particular I'd like to see an example of a bare-bones executable which does nothing ...
Matthew Murdoch's user avatar
38 votes
6 answers
76k views

Building a 32-bit float out of its 4 composite bytes

I'm trying to build a 32-bit float out of its 4 composite bytes. Is there a better (or more portable) way to do this than with the following method? #include <iostream> typedef unsigned char ...
Madgeek's user avatar
  • 383
37 votes
20 answers
5k views

How do you deal with Internet Explorer?

I am aware that there are probably other questions regarding this topic. I guess that every web developer goes through this with IE. My problem: I am developing a web-based application fully based on ...
fmsf's user avatar
  • 36.7k
37 votes
2 answers
16k views

Correct, portable way to interpret buffer as a struct

The context of my problem is in network programming. Say I want to send messages over the network between two programs. For simplicity, let's say messages look like this, and byte-order is not a ...
croyd's user avatar
  • 1,095
35 votes
4 answers
102k views

c++ Initializing a struct with an array as a member

Edited again because it originally wasn't clear that I'm trying to initialize the arrays at compile time, not at run time... I've got the following reduced testcase: typedef struct TestStruct { ...
Drew Shafer's user avatar
  • 4,810
34 votes
12 answers
53k views

How should I handle "cast from ‘void*’ to ‘int’ loses precision" when compiling 32-bit code on 64-bit machine?

I have a package that compiles and works fine on a 32-bit machine. I am now trying to get it to compile on a 64-bit machine and find the following error- error: cast from ‘void*’ to ‘int’ loses ...
badkya's user avatar
  • 697
33 votes
12 answers
20k views

How to write portable code in c++?

What are the things that I should keep in mind to write portable code? Since I'm a c++ beginner, I want to practice it since beginning. Thanks.
understack's user avatar
  • 11.4k

1
2 3 4 5
30