Programmiersprache C (C95, C99, C11, C18)

C99 Definition
NULL Pointer
C Programming/stdint.h

inttypes.h – fixed size integer types
stdint.h – integer types

Include

NULL stddef.h
size_t stddef.h
uint32_t stdint.h
stddef.h NULL, size_t
stdbool.h bool, true, false
stdint.h uint32_t
limits.h INT_MIN, UINT_MAX
inttypes.h PRId32, PRIx32

Varianten der Programmiersprache C

Präprozessor

C preprocessor

Stop on Preprocessor

Can gcc output C code after preprocessing?

$ gcc -E test.c

Concatenation

Concatenation

struct command
{
  char *name;
  void (*function) (void);
};

#define COMMAND(NAME)  { #NAME, NAME ## _command }

struct command commands[] =
{
  COMMAND (quit),
  COMMAND (help),
  …
};

/* === RESULT === */
struct command commands[] =
{
  { "quit", quit_command },
  { "help", help_command },
  …
};

Variadic macro __VA_ARGS__

Variadic Macros
Variadic macro

#define MYLOG(FormatLiteral, ...)  \
        fprintf (stderr, "%s(%u): " FormatLiteral "\n", \
        __FILE__, __LINE__, __VA_ARGS__)

Structs

struct (C programming language)

Struct initialization

Designated Initializer

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

/* Forward declare a type "point" to be a struct. */
typedef struct point point;
/* Declare the struct with integer members x, y */
struct point {
   int    x;
   int    y;
};

/* Define a variable p of type point, and
   initialize its first two members in place */
point p = {
    1,
    2
};

/* Define a variable p of type point, an
   set members using designated  initializers*/
point p = { 
    .y = 2,
    .x = 1
};

Leave a Reply

Your email address will not be published. Required fields are marked *