In this SO question I've encountered a very weird typedef:
struct Date { int day, month, year; } typedef date_s; I've always been seeing typedefs following this 'rule':
typedef <existing> <new>; For example:
typedef unsigned long long ull; typedef int kph; // speed typedef void (*alpm_cb_log)(alpm_loglevel_t, const char *, va_list); typedef int int_t; typedef char char_t, *char_p, (*fp)(void); The 4th one is taken from here, the 5th and 6th are from cppreference
And this is how I would typedef a struct:
typedef struct { int a, b, c; } data; // and then use it data Something; The question is how is this even possible to write such a typedef? It doesn't even make sense (at least to me).
clang doesn't give any errors or warnings, even with -Wall -Wextra.
Bonus question: should I advise the author of the question where this code could be found to avoid using such a typedef (because it's very unusual and may lead to confusion)?
int const imuch more thanconst int i. It's less confusing when working with pointers, since you only have to follow one general rule: "Whatever precedes const is const".int const* i;is much more concise thanconst int *i;.typedef(almost) anywhere makes it declaring a type alias instead of a variable. People usually put it at the front for clarity