I saw a question the other day where someone inadvertently used an incomplete type by specifying something like
struct a { int q; }; struct A *x; x->q = 3;
The compiler knew that struct A
was a struct, despite A
being totally undefined, by virtue of the struct
keyword.
That was in C++, where such usage of struct
is atypical (and, it turns out, can lead to foot-shooting). In C if you do
typedef struct a { ... } a;
then you can use a
as the typename and omit the struct
later. This will lead the compiler to give you an undefined identifier error later, rather than incomplete type, if you mistype the name or forget a header.
Related Posts:
- typedef struct vs struct definitions [duplicate]
- Why should we typedef a struct so often in C?
- Why should we typedef a struct so often in C?
- typedef struct vs struct definitions [duplicate]
- typedef struct pointer definition
- uint8_t vs unsigned char
- What does “collect2: error: ld returned 1 exit status” mean?
- What does “collect2: error: ld returned 1 exit status” mean?
- What does “collect2: error: ld returned 1 exit status” mean?
- How do you make an array of structs in C?
- C programming, error: called object is not a function or function pointer
- C compile error: “Variable-sized object may not be initialized”
- Difference between a Structure and a Union
- error: expected primary-expression before ‘)’ token (C)
- How to initialize a struct in accordance with C programming language standards
- Incompatible implicit declaration of built-in function ‘malloc’
- What is the cause of flexible array member not at end of struct error?
- C compile error: Id returned 1 exit status
- size of struct in C
- (.text+0x20): undefined reference to `main’ and undefined reference to function
- Why am I getting this error: “data definition has no type or storage class”?
- Scanning Multiple inputs from one line using scanf
- “warning: useless storage class specifier in empty declaration” in struct
- What causes a segmentation fault (core dump) to occur in C?
- How to use symbols of extended ASCII table in C?
- Two questions about basic C programs
- How to convert an int to string in C?
- what is the difference between uint16_t and unsigned short int incase of 64 bit processor?
- Why am I getting “void value not ignored as it ought to be”?
- 1 = false and 0 = true?
- c stack smashing detected
- What does “dereferencing” a pointer mean?
- char *array and char array[]
- Convert char to int in C and C++
- Get a substring of a char*
- What causes the Broken Pipe Error?
- Strings and character with printf
- Why does the terminal show “^[[A” “^[[B” “^[[C” “^[[D” when pressing the arrow keys in Ubuntu?
- Write to .txt file?
- What does #pragma once mean in C? [duplicate]
- Using ssize_t vs int
- Why a warning of “control reaches end of non-void function” for the main function?
- Connect: Socket operation on non-socket
- “Initializer element is not constant” in C
- How do you do exponentiation in C?
- Printing long int value in C
- Undefined reference to pow( ) in C, despite including math.h [duplicate]
- Try catch statements in C
- How do I create an array of strings in C?
- How to check if a string is a number?
- The difference between stdout and STDOUT_FILENO
- where does stdio.o live in linux machine?
- Using Dynamic Memory allocation for arrays
- Python ? (conditional/ternary) operator for assignments
- What’s the difference between a file descriptor and file pointer?
- What is a file with extension .a?
- Cygwin – Makefile-error: recipe for target `main.o’ failed
- error: indirection requires pointer operand (‘int’ invalid)
- Why am I getting “undefined reference to sqrt” error even though I include math.h header?
- Why am I getting “undefined reference to sqrt” error even though I include math.h header?
- Finding the length of a Character Array in C
- Return char[]/string from a function
- Expected declaration specifier error in function
- Valgrind: Invalid read of size 1
- Multiple definition of … linker error
- Does sizeof return the number of bytes or the number of octets of a type in C?
- Zero an array in C code
- Passing an array by reference in C?
- Excess elements in char array initializer error
- Encrypt with private key and decrypt with public key
- Warning: return from incompatible pointer type in C
- How to generate a random number between 0 and 1?
- How to properly malloc for array of struct in C
- Difference between ‘struct’ and ‘typedef struct’ in C++?
- What is the difference between stdin and STDIN_FILENO?
- Memory Clobbering Error
- Check if input is integer type in C
- Iterate through a C array
- Allocating string with malloc
- How to simply convert a float to a string in c?
- hash function for string
- double free or corruption (!prev) error in c program
- What happens during a “relocation has invalid symbol index” error?
- What does this GCC error “… relocation truncated to fit…” mean?
- Initializing array of structures
- Using floats with sprintf() in embedded C
- Printf width specifier to maintain precision of floating-point value
- Two or more data types in declaration specifiers error
- ‘sprintf’: double precision in C
- C printing bits
- Error: “Access not within mapped region at address” (Valgrind)
- How do I find the time complexity (Big O) of while loop?
- Why do we use NULL in strtok()?
- How to convert string to float?
- How does the fscanf function work?
- error: ISO C forbids nested functions – What’s wrong?
- Carriage return in C?
- Segmentation fault- strcat
- Why and when to use static structures in C programming?
- fgetc(stdin) in a loop is producing strange behaviour