What is the difference between intXX_t and int_fastXX_t?

In the C99 Standard, 7.18.1.3 Fastest minimum-width integer types. (7.18.1.3p1) “Each of the following types designates an integer type that is usually fastest225) to operate with among all integer types that have at least the specified width.” 225) “The designated type is not guaranteed to be fastest for all purposes; if the implementation has no … Read more

How to properly add hex escapes into a string-literal?

Use 3 octal digits: char problem[] = “abc\022e”; or split your string: char problem[] = “abc\x12” “e”; Why these work: Unlike hex escapes, standard defines 3 digits as maximum amount for octal escape. 6.4.4.4 Character constants … octal-escape-sequence: \ octal-digit \ octal-digit octal-digit \ octal-digit octal-digit octal-digit … hexadecimal-escape-sequence: \x hexadecimal-digit hexadecimal-escape-sequence hexadecimal-digit String literal … Read more

Does the C preprocessor strip comments or expand macros first? [duplicate]

Unfortunately, the original ANSI C Specification specifically excludes any Preprocessor features in section 4 (“This specification describes only the C language. It makes no provision for either the library or the preprocessor.”). The C99 specification handles this explicity, though. The comments are replaced with a single space in the “translation phase”, which happens prior to … Read more

C99 inline function in .c file

The inline model in C99 is a bit different than most people think, and in particular different from the one used by C++ inline is only a hint such that the compiler doesn’t complain about doubly defined symbols. It doesn’t guarantee that a function is inlined, nor actually that a symbol is generated, if it … Read more

How does the compiler allocate memory without knowing the size at compile time?

This is not a “static memory allocation”. Your array k is a Variable Length Array (VLA), which means that memory for this array is allocated at run time. The size will be determined by the run-time value of n. The language specification does not dictate any specific allocation mechanism, but in a typical implementation your … Read more

func() vs func(void) in C99

TL;DR In declarations, void func1(); // obsolescent void func2(void); the behaviour is quite different. The first one declares a function without any prototype – and it may take any number of arguments! Whereas the latter declares a function with a prototype, that has no parameters and accepts no arguments. In definitions void func1() { } // … Read more

Printf long long int in C with GCC?

If you are on windows and using mingw, gcc uses the win32 runtime, where printf needs %I64d for a 64 bit integer. (and %I64u for an unsinged 64 bit integer) For most other platforms you’d use %lld for printing a long long. (and %llu if it’s unsigned). This is standarized in C99. gcc doesn’t come … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)