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

What is the behavior of integer division?

For example, int result; result = 125/100; or result = 43/100; Will result always be the floor of the division? What is the defined behavior?
T.T.T.
  • 33,367
  • 47
  • 130
  • 168
232
votes
3 answers

Realistic usage of the C99 'restrict' keyword?

I was browsing through some documentation and questions/answers and saw it mentioned. I read a brief description, stating that it would be basically a promise from the programmer that the pointer won't be used to point somewhere else. Can anyone…
user90052
  • 2,550
  • 3
  • 16
  • 7
172
votes
4 answers

bool to int conversion

How portable is this conversion. Can I be sure that both assertions pass? int x = 4<5; assert(x==1); x = 4>5; assert(x==0); Don't ask why. I know that it is ugly. Thank you.
pic11
  • 14,267
  • 21
  • 83
  • 119
170
votes
12 answers

Standard alternative to GCC's ##__VA_ARGS__ trick?

There is a well-known problem with empty args for variadic macros in C99. example: #define FOO(...) printf(__VA_ARGS__) #define BAR(fmt, ...) printf(fmt, __VA_ARGS__) FOO("this works fine"); BAR("this breaks!"); The use of BAR() above is…
jwd
  • 10,837
  • 3
  • 43
  • 67
169
votes
4 answers

What does dot (.) mean in a struct initializer?

static struct fuse_oprations hello_oper = { .getattr = hello_getattr, .readdir = hello_readdir, .open = hello_open, .read = hello_read, }; I don't understand this C syntax well. I can't even search because I don't know the syntax's…
Benjamin
  • 10,085
  • 19
  • 80
  • 130
161
votes
5 answers

What is the difference between C, C99, ANSI C and GNU C?

I have started programming practice on codechef and have been confused by the difference between C and C99. What does C mean here? Is it C89? Check the languages at the bottom of this submit. It contains both C and C99. I found on the internet…
Aseem Bansal
  • 6,722
  • 13
  • 46
  • 84
156
votes
9 answers

Printf width specifier to maintain precision of floating-point value

Is there a printf width specifier which can be applied to a floating point specifier that would automatically format the output to the necessary number of significant digits such that when scanning the string back in, the original floating point…
Vilhelm Gray
  • 11,516
  • 10
  • 61
  • 114
150
votes
5 answers

Why does C++11 not support designated initializer lists as C99?

Consider: struct Person { int height; int weight; int age; }; int main() { Person p { .age = 18 }; } The code above is legal in C99, but not legal in C++11. What was the c++11 standard committee's rationale for excluding support…
xmllmx
  • 39,765
  • 26
  • 162
  • 323
135
votes
5 answers

Can't understand this way to calculate the square of a number

I have found a function that calculates square of a number: int p(int n) { int a[n]; //works on C99 and above return (&a)[n] - a; } It returns value of n2. Question is, how does it do that? After a little testing, I found that between…
Emanuel
  • 1,333
  • 1
  • 10
  • 11
131
votes
3 answers

How does the below program output `C89` when compiled in C89 mode and `C99` when compiled in C99 mode?

I've found this C program from the web: #include int main(){ printf("C%d\n",(int)(90-(-4.5//**/ -4.5))); return 0; } The interesting thing with this program is that when it is compiled and run in C89 mode, it prints C89 and…
Spikatrix
  • 20,225
  • 7
  • 37
  • 83
118
votes
3 answers

Is "inline" without "static" or "extern" ever useful in C99?

When I try to build this code inline void f() {} int main() { f(); } using the command line gcc -std=c99 -o a a.c I get a linker error (undefined reference to f). The error vanishes if I use static inline or extern inline instead of just…
Sven Marnach
  • 574,206
  • 118
  • 941
  • 841
118
votes
7 answers

C99 stdint.h header and MS Visual Studio

To my amazement I just discovered that the C99 stdint.h is missing from MS Visual Studio 2003 upwards. I'm sure they have their reasons, but does anyone know where I can download a copy? Without this header I have no definitions for useful types…
Rob
  • 76,700
  • 56
  • 158
  • 197
111
votes
3 answers

Are there machines, where sizeof(char) != 1, or at least CHAR_BIT > 8?

Are there machines (or compilers), where sizeof(char) != 1? Does C99 standard says that sizeof(char) on standard compliance implementation MUST be exactly 1? If it does, please, give me section number and citation. Update: If I have a machine (CPU),…
osgx
  • 90,338
  • 53
  • 357
  • 513
103
votes
12 answers

Visual Studio support for new C / C++ standards?

I keep reading about C99 and C++11 and all these totally sweet things that are getting added to the language standard that might be nice to use someday. However, we currently languish in the land of writing C++ in Visual Studio. Will any of the new…
Colen
  • 13,428
  • 21
  • 78
  • 107
98
votes
2 answers

C99 boolean data type?

What's the C99 boolean data type and how to use it?
eonil
  • 83,476
  • 81
  • 317
  • 516
1
2 3
99 100