News for hackers. Stuff that matters.
Re:Auditable Macros in C Code by bluetomcat on Friday November 24, 2017 @12:26PM (#15771901)
TL;DR

Let the compiler preprocess a source file by first removing #include lines which contain definitions of macros we don't want to see expanded (expanding only the definitions from the local file or from chosen headers, achieving less cluttered and more readable output). Say we have a file like:

    #include "foo_defs.h"
    #define BAR 42
    FOO;
    BAR;
We filter out the include line and then preprocess the file, getting the following output:

    FOO;
    42;
Re:Auditable Macros in C Code by mattip on Friday November 24, 2017 @04:45PM (#15773193)
Their technique is specific for their set of includes. It would be great if there was a general way to do the macro expansion in a need-to-know eay that could then be a basis for interop tools such as SWIG or python cffi
Re:Auditable Macros in C Code by sigjuice on Friday November 24, 2017 @02:36PM (#15772605)
TLDR of why less cluttered preprocessor output matters? I’d say cpp output is usually not that interesting on a daily basis.
Re:Auditable Macros in C Code by bluetomcat on Friday November 24, 2017 @02:48PM (#15772655)
If I have a file like this:

    #include <stdio.h>
    #include <assert.h>
    #include "mydefs-control.h"
    #include "mydefs-value.h"

    int main(void) {
        assert(1 == 1);
        printf("%d\n", MYDEF_VALUE_MACRO);
        MYDEF_MACRO_WITH_CONTROL_FLOW();
    }
My goal is to produce output which doesn't include thousands of lines from stdio.h and assert.h, doesn't expand assert() or MYDEF_VALUE_MACRO, and only expands MYDEF_MACRO_WITH_CONTROL_FLOW:

    int main(void) {
        assert(1 == 1);
        printf("%d\n", MYDEF_VALUE_MACRO);

        if (1) {
            return 0;
        } else {
            return 1;
        };
    }
According to the author, having only the "interesting" stuff expanded makes it easier to reason about the control flow of the code.
Re:Auditable Macros in C Code by dummyfunnytoo on Friday November 24, 2017 @04:44PM (#15773189)
Which just raises the question for me, why have the macros at all? I did C++ development for years (on low level and performance sensitive applications) but 95% of the macros I saw were there to reduce lines of code or "eliminate boilerplate." Almost all of those could be eliminated by refactoring within C++, without resorting to the preprocessor, but developers love using macros...
Re:Auditable Macros in C Code by sjmulder on Saturday November 25, 2017 @01:43AM (#15774764)
The article is about C where not everything can be solved with a typedef, enum or templates. Think about feature macros (e.g. _C_POSIX_SOURCE), generics (pre-C11 or what was it), attributes or calling conventions, conditional compilation, function-like macros, compatibility (e.g. errno when it isn't just an extern int), and indeed shorthands.
Re:Auditable Macros in C Code by roywiggins on Friday November 24, 2017 @06:36PM (#15773615)
I guess it standardizes your boilerplate at write-time even if you have to review it expanded.