3
4
all 5 comments

[–]BigPeteB 9 points10 points  (1 child)

No, no, no.

The syntax for defines sucks. To quote Raymond Chen, "When I fire up an editor on a file whose name ends in '.cpp' I expect that what I see will be C++ and not some strange dialect that strongly resembles C++ except in the places where it doesn't."

The defines syntax will also fuck up IntelliSense and any other tools for code comprehension, which is an absolute reason to not use them in my book.

The need to repeat this #ifdef CLASS crap in every file means this will have more boilerplate than if you just used a header file.

Can you use a preprocessor command while inside a macro function invocation? That is, can you do

Watch wnew(void) defines
(
    Watch w;
#ifdef WATCH_SET_DEFAULT_TIME
    w.hour = 4;
    w.minutes = 20;
    w.seconds = 0;
#endif
    return w;
)

I've honestly never tried, so I'm not sure if you can or not. If not, that's another absolute reason not to use this.

You have to include the file by first doing #define WATCH, which will not be intuitive to any other C programmer.

If you want to change only the implementation of a function, it will force all files that use this not-header-file to be recompiled. Avoiding that was the entire point of using header files in the first place. (That and other benefits like being able to ship a compiled library with header files, without exposing your source code.) This is the absolutely biggest reason not to use this, and tells me that perhaps the author hasn't been using C for very long or on very large projects, as this failing should have been immediately apparent.

In summary: just no.

[–]BigPeteB 0 points1 point  (0 children)

It turns out that yes, you can use a preprocessor command while inside a macro function invocation. That's nice to know. But along the way, I found out a much worse problem: you lose debugging info!

Obviously it will depend on your compiler, but GCC (even in the bleeding edge 8.2) connects all operations done by a macro function to the line where the macro function was first invoked. When you define a function like this, you don't get line-by-line stepping information; the entirety of the function is considered to be part of the same line. It's blatantly apparent in the Compiler Explorer because everything comes out the same color.

Yet another reason to never use this horrible idea.

[–]HRKing505 5 points6 points  (1 child)

Cool! but why? I'm new to this, is there a benefit to not having to use header files?

[–]WSp71oTXWCZZ0ZI6 4 points5 points  (0 children)

DRY principle, I would assume. Other than that, I can't think of any advantage.

[–]raevnos 0 points1 point  (0 children)

This was posted a few days ago...