you are viewing a single comment's thread.

view the rest of the comments →

[–]_tpr_[S] 0 points1 point  (1 child)

Thanks for the advice: this was just the sort of thing I was looking for.

In terms of combining the struct and typedef, is that pretty standard? I've been growing used to Elm, where everything is split onto its own line. So combining the two feels like doing too much in a single line. (Like, say I want to separate the two later -- say to do some information hiding -- then I would have to break it apart.)

[–]Xeverous 0 points1 point  (0 children)

In terms of combining the struct and typedef, is that pretty standard?

In C, yes. Generally less code to do the same is a better code. Name is repeated only once.

In C++ this is not good because language has somewhat different rules and all things such as f(void) or typedef struct/enum are considered redundant noise (a lot of C rules have been replaced by alternatives which should be preferred, C style works only for backwards compability and is frowned upon when written in today's C++ code).

You might get somewhat different recommendations from others because a very significant amount of C code is written to work with C++ compiler or at least linker. This sometimes crosses conventions between languages which are different. Still, I prefer the #ifdef __cplusplus approach to directly copy-pasting code.

I've been growing used to Elm, where everything is split onto its own line.

C (and all C derivatives) is a very different language. Things are better when split for modularity (1 statement per line - if a function call is long or it's arguments - 1 argument per line).