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.

Portable code can be run with little to no modification in multiple environments. This is typically achieved by either abstraction or specialization.

Abstraction is achieved by using a programming language or library which sits between your code and the platforms it runs on, attempting to obscure the differences between them. Any programming language which does not compile to native code attempts to provide some level of such abstraction.

Specialization requires writing code which is aware of the nuances of various environments and adapts to them. This technique is used by many *nix projects, often assisted by capability-detection tools.

Achieving the best possible portability may well involve using both methods in concert.

Portable applications can be run without modifying a computer's environment, such as by storing all configuration data inside the application folder rather than employing system-level configuration.

Such applications are designed to run without altering files on the computer's hard drive, including system config files, type associations, and the like. The goal of such portability is to ensure the application can run when side effects are undesirable, such as when installed on a removable drive or when a user does not have sufficient permission to install software.

1398 questions
726
votes
2 answers

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 even have the option SO_REUSEPORT. The WEB is…
Mecki
  • 106,869
  • 31
  • 201
  • 225
655
votes
14 answers

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

Is there a portable way to get the current user's username in Python (i.e., one that works under both Linux and Windows, at least). It would work like os.getuid: >>> os.getuid() 42 >>> os.getusername() 'slartibartfast' I googled around and was…
Jacob Gabrielson
  • 29,844
  • 15
  • 44
  • 60
328
votes
5 answers

Why should I not #include ?

I posted a question with my code whose only #include directive was the following: #include My teacher told me to do this, but in the comments section I was informed that I shouldn't. Why?
291
votes
8 answers

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 better? unsigned long strlen(char s[]) { unsigned…
user11954200
191
votes
9 answers

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 complaints about misssing prototypes for 'srandom',…
AShelly
  • 32,752
  • 12
  • 84
  • 142
154
votes
9 answers

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
  • 116,521
  • 48
  • 204
  • 258
137
votes
8 answers

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
  • 2,377
  • 4
  • 19
  • 9
125
votes
8 answers

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 libwsock32.a. In windows this works and I get the results.…
Prasad
  • 1,401
  • 2
  • 10
  • 7
122
votes
23 answers

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. Examples: "integers wrap around" "everyone has…
Nordic Mainframe
  • 25,439
  • 7
  • 57
  • 78
91
votes
9 answers

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 would like my C++ code to build on both platforms.…
ridiculous_fish
  • 14,125
  • 1
  • 41
  • 48
89
votes
4 answers

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, that it's available in my current compiler as…
The Quantum Physicist
  • 21,050
  • 13
  • 77
  • 143
85
votes
6 answers

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 describes how to go about doing this. How do I…
CodeBunny
  • 1,893
  • 3
  • 20
  • 32
79
votes
10 answers

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
  • 70,824
  • 28
  • 129
  • 163
78
votes
17 answers

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 / 'current_tags' is not a valid tag library:…
snakile
  • 47,358
  • 57
  • 160
  • 231
77
votes
3 answers

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, or portable? What is best practice?
fmark
  • 50,804
  • 25
  • 88
  • 106
1
2 3
93 94