portability

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

末鹿安然 提交于 2019-12-06 16:32:07
问题 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? 回答1: The intent is that a newline in a raw string literal maps to a single '\n' character. This intent is not expressed as clearly as it should be, which has led to some confusion. Citations are to the 2011 ISO C++ standard. First, here's the evidence that it maps to a single '\n' character. A note in section 2.14.5 [lex.string]

Is it safe to assume sizeof(double) >= sizeof(void*)?

狂风中的少年 提交于 2019-12-06 14:50:49
Is it safe to assume that sizeof(double) will always be greater than or equal to sizeof(void*) ? To put this in some context, is the following portable? int x = 100; double tmp; union { double dbl; void* ptr; } conv; conv.ptr = (void*)&x; tmp = conv.dbl; conv.dbl = tmp; printf("%d\n", *((int*)conv.ptr)); It does work on the few machines that I've tested it on, but I can see this going horribly wrong if sizeof(void*) > sizeof(double) . On current systems yes. double is 64 bits on all current and future systems because they're aligned with IEEE arithmetic's double-precision. It's unlikely but

Portable Eclipse with JRE

空扰寡人 提交于 2019-12-06 14:07:30
I'm not able to run a majority of programs from my work computer due to JRE <= 1.6 does not support switch statements for Strings. As I'm not able to install or update due to admin restrictions, would it be possible to create a portable Eclipse on a USB that incorporates the JRE (1.7) as well? The Eclipse part is easy. Just unzip Eclipse on your USB. You'll have to install Java to your USB. Afterwards, go into Eclipse Window -> Preferences; Java -> Installed JREs and make sure your Java JRE or JDK is listed and the default. Create your workspace on the USB, and you should be ready to go. It's

What portability issues are associated with byte-level access to pointers in C?

牧云@^-^@ 提交于 2019-12-06 12:05:42
问题 Purpose I am writing a small library for a larger project which supplies malloc/realloc/free wrapper-functions as well as a function which can tell you whether or not its parameter (of type void * ) corresponds to live (not yet freed) memory allocated and managed by the library's wrapper-functions. Let's refer to this function as isgood_memory . Internally, the library maintains a hash-table to ensure that the search performed by isgood_memory is reasonably fast. The hash-table maintains

How portable is weak linking? #pragma weak my_symbol

耗尽温柔 提交于 2019-12-06 11:31:46
How portable is weak linking? #pragma weak my_symbol I see that question: how-to-make-weak-linking-work-with-gcc discusses how to get it working. But is there a good way to do this such that gcc is not required? What is the difference between weak linking and guarding the declartion with an #ifdef? #ifndef my_weak_fn void my_weak_fn(){/* Do nothing */ return;} #endif #pragma is, by definition, not portable. And weak linking is done at link time (surprisingly enough). It allows a function (or any symbol, really) with the same signature to override another. That means a strong one will be chosen

Does SQLite have a machine portable file format that the C API can read/write?

北战南征 提交于 2019-12-06 07:58:33
问题 I've tried passing binary SQLite DBs over the network between different OSes and architectures - it didn't work. What format are you all using? I've tried an unholy hack of copying SQLite's shell.c and calling shell_main() with a hacked up argc, argv, stdin with success on Mac. Pity I'm developing for the iPhone and it fails only there. Does everyone do such awful things? 回答1: This is one of the core features of SQLite. Stable Cross-Platform Database File The SQLite file format is cross

Portable way to put stdout in binary mode

倖福魔咒の 提交于 2019-12-06 05:55:59
问题 I'm writing C programs used as cgi's that generate and output gif images. They're used in HTML pages with tags of the form <img src="/cgi-bin/gifprogram.cgi?param=val&etc"> , where the query string params describe the image to be generated by the cgi. C program cgi's invoked like this emit their output to stdout. And in this case the output's a gif image containing lots of binary (non-printable) bytes. That's already working fine on Unix/Linux. But Windows apparently requires a separate non

How to limit the execution time of a function in C/POSIX?

血红的双手。 提交于 2019-12-06 05:22:51
Similar to this question , I'd like to limit the execution time of a function--preferably with microsecond accuracy--in C. I imagine that C++ exceptions could be used to achieve a result similar to this Python solution. Though it's not ideal, such an approach is wholly unavailable in plain C. I wonder, then, how might I interrupt the execution of a function after a certain time interval in C on a Posix system? For relatively simple situations a bit of silly business works just fine, but that adds a fair amount of code orthogonal to the problem solution. Let's say I have a function like so:

Making portable code

筅森魡賤 提交于 2019-12-06 02:50:35
With all the fuss about opensource projects, how come there is still not a strong standard that enables you to make portable code (I mean in C/C++ not Java or C# ) Everyone is kind of making it's own soup. There are even some third party libs like Apache Portable Runtime . Yes, there is no standard but libraries like Qt and boost can make your life much easier when you do cross-platform development. wxwidgets is a great abstraction layer on the native GUI widgets of most window managers. I think the main reason there isn't any single library anyone agrees on is that everyone's requirements are

Maximize SDL window

[亡魂溺海] 提交于 2019-12-05 22:08:39
问题 How should I tell SDL to maximize the application window? I'm creating the window with these flags: SDL_OPENGL | SDL_HWSURFACE | SDL_DOUBLEBUF | SDL_RESIZABLE. 回答1: This functionality is controlled by the window manager when you use the SDL_RESIZABLE flag. To simulate the maximizing a window with SDL you would need to first determine the size the window would occupy when maximized. Then you would call SDL_SetVideoMode with this size after placing the window with the SDL_VIDEO_WINDOW_POS