Hacker News new | ask | show | jobs
by frou_dh 5002 days ago
I like that idea of using a (presumably unnamed) enum as a bag of constants that aren't necessarily related. From the small amount of Go I tried, its syntax for constants seemed a more evolved version of that.

What do you think is the minimum realistic preprocessor usage that can be got away with? #include + #pragma once?

2 comments

You don't need #pragma once if you don't include .h files in other .h files, or if you only have a single .h file that includes other .h files. This may sound unrealistic but there are real projects that work that way. You probably do need #include.
I'd say that it's bad to put #pragma once in your minimal set, since it's nonstandard. Why not use plain old include guards?

For me, container_of() is also indispensable. Although maybe it's on the level of 'errno' as being "not really a dirty macro".

I know - I was just spitballing the minimum number, since guards require conditionals too. Though, portability aside, you have to agree that it's simply nicer, since it plainly states the intent without requiring a little dance each time.