portability

How do I typedef an implementation-defined struct in a generic header?

我们两清 提交于 2019-12-09 06:22:21
问题 I have a C project that is designed to be portable to various (PC and embedded) platforms. Application code will use various calls that will have platform-specific implementations, but share a common (generic) API to aid in portability. I'm trying to settle on the most appropriate way to declare the function prototypes and structures. Here's what I've come up with so far: main.c: #include "generic.h" int main (int argc, char *argv[]) { int ret; gen_t *data; ret = foo(data); ... } generic.h:

Using snprintf in a cross-platform application

元气小坏坏 提交于 2019-12-09 02:51:24
问题 I am writing a C program that is expected to be compiled with all major compilers. Currently I am developing on GCC on a linux machine and will compile on MSVC before committing the code. To make the cross-compiling easy, I am compiling with -ansi and -pedantic flags. This worked well until I started using snprintf which is not available in C89 standard. GCC can compile this without the -ansi switch but MSVC will fail always as it doesn't have C99 support. So I did something like, #ifdef

Portable C++ 03 Exact Width Types

好久不见. 提交于 2019-12-09 00:44:22
问题 Background Unfortunately the current C++ standard lacks C99's exact-width types defined in the stdint header. The next best thing I could find (in terms of portability) was Boost 's cstdint.hpp implementation from the Boost.Integer library. Concerns That said, I've got a few problems with it: Boost 's implementation dumps all the typedef s in the boost namesapce (instead of something like boost::stdint ). This is totally ugly, because now you're either forced to use a using -directive only on

signed division in C

女生的网名这么多〃 提交于 2019-12-08 17:28:32
问题 I was reading the section on C portability in the book C Traps and Pitfalls by Andrew Koening.. On an integer divison q = a/b; r = a%b; If a is a negative number, apparently the reminder r can be a negative or positive number, while satisfying the property q * b + r == a Normally I would expect r to be negative if dividend a is negative. And that is what I see in a intel machine with gcc. I am just curious have you ever seen a machine that would return a positive reminder when the dividend is

ResourceMap not found error when referencing a resource file within a portable class library

半城伤御伤魂 提交于 2019-12-08 16:39:27
问题 The problem I am facing has as follows: I have developed a portable class library to encapsulate a service connection. Inside this class library there is a Resources.resw file containing strings. These strings are called only by methods of the class library (for example to override ToString() methods). As I said this is a portable class library. If I reference it as a dll, or even as a project inside another solution, it gets built and compiles correctly. Then I make a call using a method of

Portable way to get file size in C/C++

别来无恙 提交于 2019-12-08 16:37:43
问题 I need to determin the byte size of a file. The coding language is C++ and the code should work with Linux, windows and any other operating system. This implies using standard C or C++ functions/classes. This trivial need has apparently no trivial solution. 回答1: Using std's stream you can use: std::ifstream ifile(....); ifile.seekg(0, std::ios_base::end);//seek to end //now get current position as length of file ifile.tellg(); If you deal with write only file (std::ofstream), then methods are

Bit fields portability

若如初见. 提交于 2019-12-08 16:25:12
问题 I read here that bit fields are not portable. Does that mean that the code below that defines bit fields (code taken from here) could not compile on certain machines? If so, then why? #include <stdio.h> #include <string.h> /* define simple structure */ struct { unsigned int widthValidated; unsigned int heightValidated; } status1; /* define a structure with bit fields */ struct { unsigned int widthValidated : 1; unsigned int heightValidated : 1; } status2; int main( ) { printf( "Memory size

Deploying C# (.NET 2.0) application as a portable application?

偶尔善良 提交于 2019-12-08 16:19:40
问题 Is it possible to deploy a .NET 2.0 application as a portable executable? So that my program can be ran in a Flash Disk without the .NET Framework 2.0 installed in the target machine. Or maybe is it possible to distribute my program with the required .NET DLLs, so that no framework installation is necessary? I know that there are some alternative tools to turn my .NET exe into a single native executable like RemoteSoft Salamander, Xenocode Postbuild, and Thinstall, but unfortunately I can't

size of pointers and architecture

五迷三道 提交于 2019-12-08 14:42:18
问题 By conducting a basic test by running a simple C++ program on a normal desktop PC it seems plausible to suppose that sizes of pointers of any type (including pointers to functions) are equal to the target architecture bits ? For example: in 32 bits architectures -> 4 bytes and in 64 bits architectures -> 8 bytes. However I remember reading that, it is not like that in general! So I was wondering what would be such circumstances? For equality of size of pointers to data types compared with

Portable python app to run on remote systems

三世轮回 提交于 2019-12-08 12:35:00
问题 I am in need to generate a standalone portable python application and run on remote systems where even python interpreter is not installed or version is different. The aim will be to pack the python script as an app, transfer it to the remote systems and run it as a standalone app without any dependencies. Do we have such a way in the Python world? Has anybody done a similar thing before? 回答1: Freezing is the name of the game. Here's an example using PyInstaller . A sample script test.py : #!