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
47
votes
6 answers

Why was mixing declarations and code forbidden up until C99?

I have recently become a teaching assistant for a university course which primarily teaches C. The course standardized on C90, mostly due to widespread compiler support. One of the very confusing concepts to C newbies with previous Java experience…
RavuAlHemio
  • 2,331
  • 19
  • 22
47
votes
11 answers

Why didn't C have a boolean data type prior to C99?

I realise you can just #define some integers, but why didn't C have a dedicated boolean data type before C99? It's such a common occurence in programming and logic, I don't understand the absense of an explicit type and notation.
xyz
  • 27,223
  • 29
  • 105
  • 125
47
votes
6 answers

What's the C++ equivalent of UINT32_MAX?

In C99, I include stdint.h and that gives me UINT32_MAX as well as uint32_t data type. However, in C++ the UINT32_MAX gets defined out. I can define __STDC_LIMIT_MACROS before including stdint.h, but this does not work if someone is including my…
kdt
  • 27,905
  • 33
  • 92
  • 139
47
votes
7 answers

How universally is C99 supported?

How universally is the C99 standard supported in today's compilers? I understand that not even GCC fully supports it. Is this right? Which features of C99 are supported more than others, i.e. which can I use to be quite sure that most compilers will…
Eli Bendersky
  • 263,248
  • 89
  • 350
  • 412
46
votes
8 answers

What's the proper use of printf to display pointers padded with 0s

In C, I'd like to use printf to display pointers, and so that they line up properly, I'd like to pad them with 0s. My guess was that the proper way to do this was: printf("%016p", ptr); This works, but this gcc complains with the following…
Florian
44
votes
1 answer

Why does sizeof(x)++ compile?

I have run into the following code snippet: int a = 3; printf("%d", sizeof(a)++); Apparently this will compile with GCC 9.3.0 and -std=c99. While this does not compile: printf("%d", sizeof(3)++); GCC prints an error error: lvalue required as…
Eddi
  • 542
  • 3
  • 6
44
votes
3 answers

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

When I try to compile this on Linux with gcc -std=c99, the compiler complains about not knowing struct timespec. However if I compile this without -std=c99 everything works fine. #include int main(void) { struct timespec asdf; return…
Nils
  • 13,319
  • 19
  • 86
  • 108
44
votes
2 answers

Passing a multidimensional variable length array to a function

There are tons of similar questions, but still I could not find any answer relevant for the feature of variable length arrays in C99/C11. How to pass multidimensional variable length array to a function in C99/C11? For example: void foo(int n, int…
alveko
  • 2,109
  • 2
  • 18
  • 15
43
votes
7 answers

How to find my current compiler's standard, like if it is C90, etc

I'm working on a Linux machine. Is there any system command to find the standard followed by the C compiler I'm using?
Hemanth
  • 5,035
  • 9
  • 41
  • 59
43
votes
7 answers

What's the difference between "int" and "int_fast16_t"?

As I understand it, the C specification says that type int is supposed to be the most efficient type on target platform that contains at least 16 bits. Isn't that exactly what the C99 definition of int_fast16_t is too? Maybe they put it in there…
something_clever
  • 806
  • 1
  • 7
  • 17
41
votes
2 answers

difference between c99 and c11

I am learning c, presently. The book I read is C99 based. I want to update my knowledge to C11 after finishing this book, or change resource if there is a major difference. Thus, what I ask is for is an explanation or resource to update my…
41
votes
3 answers

Tentative definitions in C and linking

Consider the C program composed of two files, f1.c: int x; f2.c: int x=2; My reading of paragraph 6.9.2 of the C99 standard is that this program should be rejected. In my interpretation of 6.9.2, variable x is tentatively defined in f1.c, but this…
Pascal Cuoq
  • 79,187
  • 7
  • 161
  • 281
40
votes
4 answers

Create statically-linked binary that uses getaddrinfo?

I have included the header netdb.h, where getaddrinfo is included, but gcc issues this warning: warning: Using 'getaddrinfo' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking gcc -m32…
Neeladri Vishweswaran
  • 1,695
  • 5
  • 22
  • 40
39
votes
7 answers

How can I return an anonymous struct in C?

Trying some code, I realized that the following code compiles: struct { int x, y; } foo(void) { } It seems as if we are defining a function named foo which returns an anonymous struct. Does it only happen to compile with my compiler or is this…
Askaga
  • 6,061
  • 5
  • 25
  • 49
39
votes
2 answers

Signedness of enum in C/C99/C++/C++x/GNU C/GNU C99

Is the enum type signed or unsigned? Does the signedness of enums differ between: C/C99/ANSI C/C++/C++x/GNU C/ GNU C99? Thanks
osgx
  • 90,338
  • 53
  • 357
  • 513