News for hackers. Stuff that matters.
Re:µUBSan: clean-room reimplementation of the Undefined Beha... by TeMPOraL on Wednesday August 08, 2018 @12:13PM (#17717121)
Not really. All you need to do is:

  #ifndef __onefilelib__
  #define __onefilelib__
  #include "onefilelib.c"
  #endif
(Also potentially defining "main" as something else, if it happens that the "onefilelib.c" has an entry point for some reason.)
Re:µUBSan: clean-room reimplementation of the Undefined Beha... by abenedic on Wednesday August 08, 2018 @01:36PM (#17717771)
You should really be careful about c preprocessor macros when you do things like this with .c files. You should always undefine any macros defined in a file which are not properly namespaced(as much as C allows for pseudo namespacing).
Re:µUBSan: clean-room reimplementation of the Undefined Beha... by slrz on Wednesday August 08, 2018 @04:30PM (#17719202)
This only does what you want if you mush everything together into a single translation unit. Otherwise, you will get duplicate definitions for everything in onefilelib.c.
Re:µUBSan: clean-room reimplementation of the Undefined Beha... by sigjuice on Wednesday August 08, 2018 @02:36PM (#17718260)
Is there a prominent C code base that does this sort of thing? I’m sorry this is all very questionable advice IMHO. What would be one word in a makefile (onefilelib.c) is a 4-line jumble of preprocessor macros, names starting with __ are reserved, and the suggestion to redefine main and entry points smells like more #ifdef spaghetti.
Re:µUBSan: clean-room reimplementation of the Undefined Beha... by mnarayan01 on Wednesday August 08, 2018 @02:53PM (#17718402)
The #ifndef rigamarole is https://en.wikipedia.org/wiki/Include_guard and at least used to be fairly common. I also used to see the __FOO_BAR_H__ naming convention for these defines all over the place. I'm not sure if __ identifiers being reserved is a (not very) new thing or if it's always been around and people are just now more generally knowledgeable about the fact that they shouldn't be used.
Re:µUBSan: clean-room reimplementation of the Undefined Beha... by sigjuice on Wednesday August 08, 2018 @03:00PM (#17718459)
Yes, the include guard is a very widespread technique for header files. My objection is against #include’ing a .c file to support the questionable trend of ‘single file libs’.
Re:µUBSan: clean-room reimplementation of the Undefined Beha... by TeMPOraL on Wednesday August 08, 2018 @03:48PM (#17718849)
I wasn't suggesting this as a serious method of organizing your project - merely pointing out that this quick hack can be done and is rather straightforward. And I did actually see it once or twice in the wild.
Re:µUBSan: clean-room reimplementation of the Undefined Beha... by abenedic on Wednesday August 08, 2018 @02:41PM (#17718300)
I am not sure of a prominent code base that does this exactly, but some people do similar things with "amalagmated builds". Like https://www.sqlite.org/amalgamation.html