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
97
votes
9 answers

Difference between uint8_t, uint_fast8_t and uint_least8_t

The C99 standard introduces the following datatypes. The documentation can be found here for the AVR stdint library. uint8_t means it's an 8-bit unsigned type. uint_fast8_t means it's the fastest unsigned int with at least 8 bits. uint_least8_t…
mic
  • 1,165
  • 1
  • 9
  • 8
94
votes
3 answers

Printing null pointers with %p is undefined behavior?

Is it undefined behavior to print null pointers with the %p conversion specifier? #include int main(void) { void *p = NULL; printf("%p", p); return 0; } The question applies to the C standard, and not to C implementations.
Dror K.
  • 1,989
  • 17
  • 26
92
votes
10 answers

Is it possible to iterate over arguments in variadic macros?

I was wondering if it is possible to iterate over arguments passed to a variadic macro in C99 or using any GCC extensions ? For e.g. is it possible to write a generic macro that takes a structure and its fields passed as arguments and prints offset…
vshenoy
  • 1,153
  • 1
  • 8
  • 14
82
votes
6 answers

What is the use of the `inline` keyword in C?

I read several questions in stackoverflow about inline in C but still am not clear about it. static inline void f(void) {} has no practical difference with static void f(void) {}. inline void f(void) {} in C doesn't work as the C++ way. How does it…
user3810155
81
votes
5 answers

Why are there digraphs in C and C++?

I learned today that there are digraphs in C99 and C++. The following is a valid program: %:include %:ifndef BUFSIZE %:define BUFSIZE 512 %:endif void copy(char d<::>, const char s<::>, int len) <% while (len-- >= 0) <% …
Sydius
  • 13,567
  • 17
  • 59
  • 76
81
votes
8 answers

state machines tutorials

I am just wondering if anyone know of some good tutorials on the Internet for developing state machines. Or ebooks? I am starting working on state machines and just need something general to get me started.
ant2009
  • 27,094
  • 154
  • 411
  • 609
80
votes
4 answers

Is the behavior of subtracting two NULL pointers defined?

Is the difference of two non-void pointer variables defined (per C99 and/or C++98) if they are both NULL valued? For instance, say I have a buffer structure that looks like this: struct buf { char *buf; char *pwrite; char *pread; } ex; Say,…
John Luebs
  • 861
  • 6
  • 8
80
votes
17 answers

What are the most useful new features in C99?

C99 has been around for over 10 years, but support for it has been slow coming, so most developers have stuck with C89. Even today, I'm sometimes mildly surprised when I come across C99 features in C code. Now that most major compilers support C99…
Brian Campbell
  • 322,767
  • 57
  • 360
  • 340
80
votes
7 answers

What is the default C -std standard version for the current GCC (especially on Ubuntu)?

When I ask to see the current version of cc I get this. $ cc --version cc (Ubuntu/Linaro 4.7.2-2ubuntu1) 4.7.2 Copyright (C) 2012 Free Software Foundation, Inc. This is free software; see the source for copying conditions. There is NO warranty; not…
ncmathsadist
  • 4,684
  • 3
  • 29
  • 45
73
votes
4 answers

func() vs func(void) in C99

void func() In practice, an empty parameter means any argument is accepted. void func(void) accepts no argument. But in Standard C99, I find such lines: 6.7.5.3 Function declarators (including prototypes) 14 An identifier list declares only the…
liusrichard
  • 733
  • 5
  • 8
73
votes
3 answers

Setting std=c99 flag in GCC

I was wondering if there were any files in which I could set the -std=c99 flag, so that I would not have to set it for every compilation. I am using GCC 4.4 on Ubuntu.
Fatmarik
  • 969
  • 2
  • 9
  • 11
71
votes
4 answers

Printf long long int in C with GCC?

How do I printf long long int and also unsigned long long int in C99 using GCC? I have searched the other posts which suggest to use %lld but it gives these warnings: warning#1: unknown conversion type character 'l' in format [-Wformat]| …
user963241
  • 6,758
  • 19
  • 65
  • 93
70
votes
4 answers

Is type-punning through a union unspecified in C99, and has it become specified in C11?

A number of answers for the Stack Overflow question Getting the IEEE Single-precision bits for a float suggest using a union structure for type punning (e.g.: turning the bits of a float into a uint32_t): union { float f; uint32_t u; }…
sfstewman
  • 5,589
  • 1
  • 19
  • 26
68
votes
3 answers

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

When you have string in C, you can add direct hex code inside. char str[] = "abcde"; // 'a', 'b', 'c', 'd', 'e', 0x00 char str2[] = "abc\x12\x34"; // 'a', 'b', 'c', 0x12, 0x34, 0x00 Both examples have 6 bytes in memory. Now the problem exists if…
unalignedmemoryaccess
  • 7,246
  • 2
  • 25
  • 40
68
votes
3 answers

C99 inline function in .c file

I defined my function in .c (without header declaration) as here: inline int func(int i) { return i+1; } Then in the same file below I use it: ... i = func(i); And during the linking I got "undefined reference to 'func'". Why?
user14416
  • 2,922
  • 5
  • 40
  • 67