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
22
votes
4 answers

How to compile a C project in C99 mode?

I got the following error message while compiling the C code: error: 'for' loop initial declarations are only allowed in C99 mode note: use option -std=c99 or -std=gnu99 to compile your code What does it mean? How to fix it?
mpluse
  • 1,857
  • 6
  • 18
  • 25
22
votes
2 answers

__func__ outside function definition

What should happened if we use predefined variable __func__ outside a function in C (C99 / C11) and C++? #include const char* str = __func__; int main(void) { printf("%s", str); return 0; } gcc 4.7.2 only give a warning (with…
FrozenHeart
  • 19,844
  • 33
  • 126
  • 242
22
votes
1 answer

When __builtin_memcpy is replaced with libc's memcpy

There is a version of C99/posix memcpy function in GCC: __builtin_memcpy. Sometimes it can be replaced by GCC to inline version of memcpy and in other cases it is replaced by call to libc's memcpy. E.g. it was noted here: Finally, on a compiler…
osgx
  • 90,338
  • 53
  • 357
  • 513
21
votes
3 answers

Forward declaration of inline functions

I have a header file that is going to contain a large amount (30+) of inline functions. Rather than having the reader scroll or search for the definition (implementation) of the inline function, I would like to have a forward declaration section…
Thomas Matthews
  • 56,849
  • 17
  • 98
  • 154
21
votes
2 answers

is i=f(); defined when f modifies i?

Related question: Any good reason why assignment operator isn't a sequence point? From the comp.lang.c FAQ I would infer that the program below is undefined. Strangely, it only mentions the call to f as a sequence point, between the computation of…
Pascal Cuoq
  • 79,187
  • 7
  • 161
  • 281
21
votes
1 answer

What is the official status of C99 support in VS2013?

I see that VS2013 added support for a large number of major core language features of C99. Now it supports compound literals, designated initializers, variadic macros, interleaved declarations and statements just to name a few. This indicates that…
AnT stands with Russia
  • 312,472
  • 42
  • 525
  • 765
21
votes
1 answer

Get warning when a variable is shadowed

I generally want to avoid code like this: #include int main(int argc, char *argv[]){ int n = 3; for (int n = 1; n <= 10; n++){ printf("%d\n", n); } printf("%d\n", n); } How can I find such usage of variables? That means,…
Ystar
  • 351
  • 1
  • 3
  • 8
21
votes
2 answers

What are "extended integer types"?

Quoting from the book I'm reading: signed char, signed short int, signed int, signed long int, signed long long int are called standard signed integer types unsigned char, unsigned short int, unsigned int, unsigned long int, unsigned long long…
claws
  • 52,236
  • 58
  • 146
  • 195
20
votes
8 answers

Which version of C is more appropriate for students to learn- C89/90 or C99?

I'm looking into learning C basics and syntax before beginning Systems Programming next month. When doing some reading, I came across the C89/99 standards. According to Wikipedia, C99 introduced several new features, including inline…
Jason
  • 11,263
  • 21
  • 87
  • 181
20
votes
2 answers

Does either ANSI C or ISO C specify what -5 % 10 should be?

I seem to remember that ANSI C didn't specify what value should be returned when either operand of a modulo operator is negative (just that it should be consistent). Did it get specified later, or was it always specified and I am remembering…
Chas. Owens
  • 64,182
  • 22
  • 135
  • 226
20
votes
3 answers

Allocating char array using malloc

Considering the following line: char *p = malloc( sizeof(char) * ( len + 1 ) ); Why is sizeof(char) used? It's not necessary, is it? Or Is it just a matter of style? What advantages does it have?
Nyan
  • 2,360
  • 3
  • 25
  • 38
20
votes
4 answers

GCC: accuracy of strict aliasing warnings

I'm trying to check some of my code for strict aliasing violations, but it looks like I've missed something while trying to understand the strict aliasing rule. Imagine the following code: #include int main( void ) { unsigned long…
Macmade
  • 52,708
  • 13
  • 106
  • 123
20
votes
1 answer

Catch incorrect usage of c bool

In a C project (OpenVPN is the project in question, commit 4029971240b6274b9b30e76ff74c7f689d7d9750) we had a emulation of bool typedef int bool; #define false 0 #define true 1 and now switch to C99 bool #include But in the project…
plaisthos
  • 6,255
  • 6
  • 35
  • 63
20
votes
4 answers

Should I use ANSI C (C89)?

It's 2012. I'm writing some code in C. Should I be still be using C89? Are there still compilers that do not support C99? I don't mind using /* */ instead of //. I'm not sure about C89 forbids mixing declarations and code. I'm kind of leaning…
mk12
  • 25,873
  • 32
  • 98
  • 137
19
votes
3 answers

Reasons not to use _Bool in Objective-C?

Since C99, C now has a proper Boolean type, _Bool. Objective-C, as a strict superset of C, inherits this, but when it was created back in the 1980s, there was no C Boolean type, so Objective-C defined BOOL as signed char. All of Cocoa uses BOOL, as…
Peter Hosey
  • 95,783
  • 15
  • 211
  • 370