News for hackers. Stuff that matters.
Re:Is the C++ preprocessor still needed? by mabynogy on Monday May 08, 2017 @06:29PM (#14296225)
I use the gcc preprocessor in Javascript (to avoid modules and tools like browserify):

    out="out/make1.js"
    main="make1/main.js"
    gcc -C -E -H -P -nostdinc -undef -x c $main -o $out
    node --harmony $out $@
Re:Is the C++ preprocessor still needed? by pierrec on Tuesday May 09, 2017 @11:29PM (#14305721)
As another abuser of the C preprocessor, I'll point out that you can greatly simplify your call to gcc... by not using gcc, just call cpp directly:

    cpp -P -H $main $out
should be equivalent, unless I'm missing something. And since somebody was asking why use -H, I'm guessing it's just for the useful verbosity of it. I've found it also causes helpful notices to be printed like "header guards may be useful for the following file..."
Re:Is the C++ preprocessor still needed? by mkup on Wednesday May 10, 2017 @12:06PM (#14309288)
Yes, preprocessor is available as a standalone tool for preprocessing source files in assembly language (.S = input file before preprocessing, .s = output file after preprocessing or source file which does not require preprocessing).

Of course standalone preprocessor can be (ab)used to preprocess Javascript source files and any other files, as grandparent commenter suggested.

Re:Is the C++ preprocessor still needed? by ndesaulniers on Tuesday May 09, 2017 @09:49PM (#14305352)
looked up these flags, since I didn't know all of them:

-C: compile but do not link (I think this is covered by -E)

-E: stop after running the preprocessor

-H: print the name of each header file included, indenting child #includes (what do you use this for? is it printed to stderr?)

-P: inhibit the generation of line markers from the preprocessor (I've used this before, but can't recall the problem it solves? Not expanding __LINE__?)

-nostdinc: do not search standard system directories for header files (/usr/include, /usr/local/include, ..., this is standard in the Linux kernel, since there is no libc)

-undef: do not predefine any system-specific or GCC macros (probably to not expand occurrences of sequences like "__GNUC__" and others from unexpectedly being expanded).

-x <language>: specify the language, rather then letting the compiler guess based on the file extension (is this required?)

Re:Is the C++ preprocessor still needed? by Goopplesoft on Tuesday May 09, 2017 @11:45PM (#14305782)
Thanks. Also, this site also seems to have args from man pages: https://explainshell.com/explain?cmd=gcc+-C+-E+-H+-P+-nostdi...
Re:Is the C++ preprocessor still needed? by ndesaulniers on Wednesday May 10, 2017 @02:55AM (#14306360)
That's a neat utility! Thanks for sharing.
Re:Is the C++ preprocessor still needed? by ksherlock on Wednesday May 10, 2017 @01:00PM (#14309728)
> -P: inhibit the generation of line markers from the preprocessor (I've used this before, but can't recall the problem it solves? Not expanding __LINE__?)

It prevents #line directives which are useful for a C compiler but erroneous for javascript.

Re:Is the C++ preprocessor still needed? by dima55 on Wednesday May 10, 2017 @01:37AM (#14306132)
you mixed up -c and -C. Here he's preserving comments
Re:Is the C++ preprocessor still needed? by kevin_thibedeau on Tuesday May 09, 2017 @08:16PM (#14304964)
You would be better served with m4.
Re:Is the C++ preprocessor still needed? by flukus on Wednesday May 10, 2017 @03:43AM (#14306530)
I looked into m4 recently but it seems to be about the worst template engine imaginable. I'd take the c pre-processor over that any day.

In the end I opted for a sed/awk/cat combo instead.

Re:Is the C++ preprocessor still needed? by daxelrod on Wednesday May 10, 2017 @08:09AM (#14307540)
Could you please point to some good m4 learning and reference resources?

The only time I had to write m4 was admittedly in the context of autotools, but I found it really difficult to get answers to my questions about how everything worked.

Re:Is the C++ preprocessor still needed? by s_kilk on Wednesday May 10, 2017 @09:05AM (#14307821)
I wrote up a little tutorial on using m4 as a CSS pre-processor:

http://blog.00null.net/post/144763147991/use-the-unix-m4-as-...

Re:Is the C++ preprocessor still needed? by flukus on Wednesday May 10, 2017 @11:04PM (#14313572)
Wow thanks, that's a much better intro to the ones I cam across like this (http://mbreen.com/m4.html). I may have to reevaluate it.
Re:Is the C++ preprocessor still needed? by slackingoff2017 on Tuesday May 09, 2017 @09:53PM (#14305375)
What the fuck! I don't know if you're a genius or just really crazy
Re:Is the C++ preprocessor still needed? by AceJohnny2 on Tuesday May 09, 2017 @10:04PM (#14305419)
Meh, it's just using the C PreProcessor, cpp, but driven through GCC.

The C preprocessor is pretty simple (well, until you start wanting to evaluate C expressions as part of your #ifdefs) and very well-known. It's not inherently tied to C (QED), so it makes sense. There are other cases where people use it on something other than C, but as kevin_thibedeau mentions, he'd be better served with a more powerful (and generic) macro processor such as M4.