GCC with -std=c99 complains about not knowing struct timespec

Explicitly enabling POSIX features The timespec comes from POSIX, so you have to ‘enable’ POSIX definitions: #if __STDC_VERSION__ >= 199901L #define _XOPEN_SOURCE 600 #else #define _XOPEN_SOURCE 500 #endif /* __STDC_VERSION__ */ #include <time.h> void blah(struct timespec asdf) { } int main() { struct timespec asdf; return 0; } The stanza at the top is what … Read more

How universally is C99 supported?

If you want to write portable C code, then I’d suggest you to write in C89 (old ANSI C standard). This standard is supported by most compilers. The Intel C Compiler has very good C99 support and it produces fast binaries. (Thanks 0x69!) MSVC supports some new features and Microsoft plan to broaden support in … Read more

What’s the C++ equivalent of UINT32_MAX?

Not sure about uint32_t, but for fundamental types (bool, char, signed char, unsigned char, wchar_t, short, unsigned short, int, unsigned int, long, unsigned long, float, double and long double) you can use the numeric_limits templates via #include <limits>. cout << “Minimum value for int: ” << numeric_limits<int>::min() << endl; cout << “Maximum value for int: … Read more

How to wrap printf() into a function or macro?

There are 2 ways to do this: Variadric macro #define my_printf(…) printf(__VA_ARGS__) function that forwards va_args #include <stdarg.h> #include <stdio.h> void my_printf(const char *fmt, …) { va_list args; va_start(args, fmt); vprintf(fmt, args); va_end(args); } There are also vsnprintf, vfprintf and whatever you can think of in stdio.

Is there a document describing how Clang handles excess floating-point precision?

This does not answer the originally posed question, but if you are a programmer working with similar issues, this answer might help you. I really don’t see where the perceived difficulty is. Providing strict IEEE-754 binary64 semantics while being limited to 80387 floating-point math, and retaining 80-bit long double computation, seems to follow well-specified C99 … Read more

Maximum size of size_t

The standard says that SIZE_MAX must be at least 65535. It specifies no upper bound, and gcc’s implementation is perfectly valid. Quoting the reference you cited (emphasis added): Its implementation-defined value shall be equal to or greater in magnitude (absolute value) than the corresponding value given below, with the same sign.

Anonymous union within struct not in c99?

Anonymous unions are a GNU extension, not part of any standard version of the C language. You can use -std=gnu99 or something like that for c99+GNU extensions, but it’s best to write proper C and not rely on extensions which provide nothing but syntactic sugar… Edit: Anonymous unions were added in C11, so they are … Read more