Questions tagged [c99]

This tag is for questions regarding the International Standard ISO 9899:1999, aka "C99", with technical corrigenda, and for questions about code written in C99 (as opposed to K&R C, C89 or later C Standard revisions like the 2011 revision C11).

This tag is for questions regarding the International Standard ISO 9899:1999 , aka "C99", with technical corrigenda, and for questions about code written in C99 (as opposed to K&R C, C89 or later C Standard revisions like the 2011 revision C11).

Always use the tag for all your C questions, then complement it with the tags for questions that are specific to this version of the standard.

1900 questions
38
votes
5 answers

How to implement memmove in standard C without an intermediate copy?

From the man page on my system: void *memmove(void *dst, const void *src, size_t len); DESCRIPTION The memmove() function copies len bytes from string src to string dst. The two strings may overlap; the copy is always done in a…
Pascal Cuoq
  • 79,187
  • 7
  • 161
  • 281
38
votes
7 answers

Can GCC warn me about modifying the fields of a const struct in C99?

I stumbled upon a small issue while trying to make const-correct code. I would have liked to write a function that takes a pointer to a const struct, to tell to the compiler "please tell me if I am modifying the struct, because I really do not want…
Samuel Navarro Lou
  • 1,168
  • 6
  • 17
38
votes
5 answers

Why is int x[n] wrong where n is a const value?

I cannot understand why doing this is wrong: const int n = 5; int x[n] = { 1,1,3,4,5 }; even though n is already a const value. While doing this seems to be right for the GNU compiler: const int n = 5; int x[n]; /*without initialization*/ I'm…
Yahia Farghaly
  • 857
  • 2
  • 10
  • 20
37
votes
2 answers

Which C99 features are available in the MS Visual Studio compiler?

It's well known that Microsoft's Visual Studio compiler does not support C99, and it looks like they have no plans to support it. However, the compiler does include some cherry picked features such as variadic macros and long long - see the quotes…
Timothy Jones
  • 21,495
  • 6
  • 60
  • 90
37
votes
4 answers

Bizarre use of conditional operator in Linux

In the 3.0.4 Linux kernel, mm/filemap.c has this line of code: retval = retval ?: desc.error; I've tried compiling a similar minimal test case with gcc -Wall and don't get any warnings; the behavior seems identical to: retval = retval ? retval :…
Conrad Meyer
  • 2,851
  • 21
  • 24
37
votes
1 answer

C program yielding different results on different machines despite using the same fixed length data types

Simple program I made when I was experimenting with inttypes.h: #include #include #include bool get_bit(uint32_t x, uint8_t n) { x >>= n; return x & 1; } int main() { uint32_t x; uint8_t n; …
Clyde B.
  • 399
  • 2
  • 4
36
votes
5 answers

Implicit declaration of function - C99

I am currently using Xcode 4, and in my .pch file I have this macro: #define localize(s) NSLocalizedString((s), nil). When I try to use this macro in some .m file, I receive this warning: Implicit declaration of function 'localize' is invalid in…
Misa
  • 889
  • 1
  • 10
  • 20
34
votes
1 answer

How do you configure GCC in Eclipse to use C99?

I'm working on a small C project in Eclipse; I just installed Eclipse from the Ubuntu Software Center and added C/C++ Language Support. I can build, run, and debug simple C programs fine. But I'm using some C99 features now, and Eclipse complains,…
Dai
  • 141,631
  • 28
  • 261
  • 374
34
votes
7 answers

Forcing C99 in CMake (to use 'for' loop initial declaration)

I've been searching a portable way to force CMake to enable the compiler's C99 features in order to avoid the following gcc error for instance: error: ‘for’ loop initial declarations are only allowed in C99 mode for (int s = 1; s <=…
Tarc
  • 3,214
  • 3
  • 29
  • 41
33
votes
5 answers

Enabling VLAs (variable length arrays) in MS Visual C++?

How can I enable the use of VLAs, variable length arrays as defined in C99, in MS Visual C++ or that is not possible at all? Yes I know that the C++ standard is based on C89 and that VLAs are not available in C89 standard and thus aren't available…
Shinnok
  • 6,279
  • 6
  • 31
  • 44
33
votes
4 answers

Literal string initializer for a character array

In the following rules for the case when array decays to pointer: An lvalue [see question 2.5] of type array-of-T which appears in an expression decays (with three exceptions) into a pointer to its first element; the type of the resultant pointer…
Tim
  • 1
  • 141
  • 372
  • 590
32
votes
18 answers

The most useful user-made C-macros (in GCC, also C99)?

What C macro is in your opinion is the most useful? I have found the following one, which I use to do vector arithmetic in C: #define v3_op_v3(x, op, y, z) {z[0]=x[0] op y[0]; \ z[1]=x[1] op y[1]; \ …
psihodelia
  • 29,566
  • 35
  • 108
  • 157
32
votes
1 answer

What are those strange array sizes [*] and [static] in C99?

Apparently the following function prototypes are valid in C99 and C11: void foo(int a[const *]); void bar(int a[static volatile 10]); What is the purpose of those strange subscript notations *, static, and CV qualifiers? Do they help distinguish…
Kerrek SB
  • 464,522
  • 92
  • 875
  • 1,084
31
votes
3 answers

How to do an explicit fall-through in C

The newer versions of gcc offer the Wimplicit-fallthrough, which is great to have for most switch statements. However, I have one switch statement where I want to allow fall throughs from all case-statements. Is there a way to do an explicit fall…
dlasalle
  • 1,615
  • 3
  • 19
  • 25
30
votes
4 answers

C type casts and addition precedence

What's the precedence in the next expression? item = (char*)heap + offset; Is it (char*)(heap + offset) or ((char*)heap) + offset?
Cheery
  • 24,645
  • 16
  • 59
  • 83