home.social

#ifndef — Public Fediverse posts

Live and recent posts from across the Fediverse tagged #ifndef, aggregated by home.social.

  1. CW: C/C++ hot take

    as far as I can tell header files have no advantages over just putting your forward declarations at the top of your .c / .cpp files

    like it’s bad enough that you have to declare everything twice, but putting your second declaration in a totally separate file that you have to remember to keep updated? that will definitely bite you in the ass

    also the existence of header files requires you to use some arcane rube goldberg build system like make that’s held together with chewing gum and rubber bands, and probably isn’t even portable. when instead you could literally just include your .c / .cpp files directly and bypass that whole process

    and it’s not even hard to write a .c/.cpp file that doesn’t need a headerfile:

    // inside of funcs.cpp:
    #ifndef FUNCS_CPP
    #define FUNCS_CPP
    int someFunc();
    int someFunc() { return 666; }
    #endif
    
    // and you just import it like this:
    #include "./funcs.cpp"
    

    like why didn’t people figure this out decades ago. who even thought that headerfiles were a good idea. maybe I’m missing something but they genuinely seem to have only downsides and aren’t even the obvious way to solve this problem?

  2. CW: C/C++ hot take

    as far as I can tell header files have no advantages over just putting your forward declarations at the top of your .c / .cpp files

    like it’s bad enough that you have to declare everything twice, but putting your second declaration in a totally separate file that you have to remember to keep updated? that will definitely bite you in the ass

    also the existence of header files requires you to use some arcane rube goldberg build system like make that’s held together with chewing gum and rubber bands, and probably isn’t even portable. when instead you could literally just include your .c / .cpp files directly and bypass that whole process

    and it’s not even hard to write a .c/.cpp file that doesn’t need a headerfile:

    // inside of funcs.cpp:
    #ifndef FUNCS_CPP
    #define FUNCS_CPP
    int someFunc();
    int someFunc() { return 666; }
    #endif
    
    // and you just import it like this:
    #include "./funcs.cpp"
    

    like why didn’t people figure this out decades ago. who even thought that headerfiles were a good idea. maybe I’m missing something but they genuinely seem to have only downsides and aren’t even the obvious way to solve this problem?

  3. CW: C/C++ hot take

    as far as I can tell header files have no advantages over just putting your forward declarations at the top of your .c / .cpp files

    like it’s bad enough that you have to declare everything twice, but putting your second declaration in a totally separate file that you have to remember to keep updated? that will definitely bite you in the ass

    also the existence of header files requires you to use some arcane rube goldberg build system like make that’s held together with chewing gum and rubber bands, and probably isn’t even portable. when instead you could literally just include your .c / .cpp files directly and bypass that whole process

    and it’s not even hard to write a .c/.cpp file that doesn’t need a headerfile:

    // inside of funcs.cpp:
    #ifndef FUNCS_CPP
    #define FUNCS_CPP
    int someFunc();
    int someFunc() { return 666; }
    #endif
    
    // and you just import it like this:
    #include "./funcs.cpp"
    

    like why didn’t people figure this out decades ago. who even thought that headerfiles were a good idea. maybe I’m missing something but they genuinely seem to have only downsides and aren’t even the obvious way to solve this problem?

  4. CW: C/C++ hot take

    as far as I can tell header files have no advantages over just putting your forward declarations at the top of your .c / .cpp files

    like it’s bad enough that you have to declare everything twice, but putting your second declaration in a totally separate file that you have to remember to keep updated? that will definitely bite you in the ass

    also the existence of header files requires you to use some arcane rube goldberg build system like make that’s held together with chewing gum and rubber bands, and probably isn’t even portable. when instead you could literally just include your .c / .cpp files directly and bypass that whole process

    and it’s not even hard to write a .c/.cpp file that doesn’t need a headerfile:

    // inside of funcs.cpp:
    #ifndef FUNCS_CPP
    #define FUNCS_CPP
    int someFunc();
    int someFunc() { return 666; }
    #endif
    
    // and you just import it like this:
    #include "./funcs.cpp"
    

    like why didn’t people figure this out decades ago. who even thought that headerfiles were a good idea. maybe I’m missing something but they genuinely seem to have only downsides and aren’t even the obvious way to solve this problem?

  5. CW: C/C++ hot take

    as far as I can tell header files have no advantages over just putting your forward declarations at the top of your .c / .cpp files

    like it’s bad enough that you have to declare everything twice, but putting your second declaration in a totally separate file that you have to remember to keep updated? that will definitely bite you in the ass

    also the existence of header files requires you to use some arcane rube goldberg build system like make that’s held together with chewing gum and rubber bands, and probably isn’t even portable. when instead you could literally just include your .c / .cpp files directly and bypass that whole process

    and it’s not even hard to write a .c/.cpp file that doesn’t need a headerfile:

    // inside of funcs.cpp:
    #ifndef FUNCS_CPP
    #define FUNCS_CPP
    int someFunc();
    int someFunc() { return 666; }
    #endif
    
    // and you just import it like this:
    #include "./funcs.cpp"
    

    like why didn’t people figure this out decades ago. who even thought that headerfiles were a good idea. maybe I’m missing something but they genuinely seem to have only downsides and aren’t even the obvious way to solve this problem?

  6. @pythno or do it the other way around:
    #ifndef ACTUALLY_BUILDING
    #define MY_...
    #endif
    and pass -DACTUALLY_BUILDING=1 to the compiler commandline (and probably don't commit that part of the code, as it's just a hack for development)

  7. @pythno or do it the other way around:
    #ifndef ACTUALLY_BUILDING
    #define MY_...
    #endif
    and pass -DACTUALLY_BUILDING=1 to the compiler commandline (and probably don't commit that part of the code, as it's just a hack for development)

  8. @pythno or do it the other way around:
    #ifndef ACTUALLY_BUILDING
    #define MY_...
    #endif
    and pass -DACTUALLY_BUILDING=1 to the compiler commandline (and probably don't commit that part of the code, as it's just a hack for development)

  9. @pythno or do it the other way around:
    #ifndef ACTUALLY_BUILDING
    #define MY_...
    #endif
    and pass -DACTUALLY_BUILDING=1 to the compiler commandline (and probably don't commit that part of the code, as it's just a hack for development)

  10. @funkylab it’s really to do with it not being standardised more than anything else. Like what is the expectation of preprocessing the following file lol.h

    #ifndef foo
    #define foo
    #else
    #pragma once
    #endif
    #include "lol.h"
    Yo

    Is it a single “Yo” or two lines of “Yo”?

    If it was defined that it needed to be the first thing in a file following whitespace, I think i’f be fine with it.

  11. @funkylab it’s really to do with it not being standardised more than anything else. Like what is the expectation of preprocessing the following file lol.h

    #ifndef foo
    #define foo
    #else
    #pragma once
    #endif
    #include "lol.h"
    Yo

    Is it a single “Yo” or two lines of “Yo”?

    If it was defined that it needed to be the first thing in a file following whitespace, I think i’f be fine with it.

  12. @funkylab it’s really to do with it not being standardised more than anything else. Like what is the expectation of preprocessing the following file lol.h

    #ifndef foo
    #define foo
    #else
    #pragma once
    #endif
    #include "lol.h"
    Yo

    Is it a single “Yo” or two lines of “Yo”?

    If it was defined that it needed to be the first thing in a file following whitespace, I think i’f be fine with it.

  13. @funkylab it’s really to do with it not being standardised more than anything else. Like what is the expectation of preprocessing the following file lol.h

    #ifndef foo
    #define foo
    #else
    #pragma once
    #endif
    #include "lol.h"
    Yo

    Is it a single “Yo” or two lines of “Yo”?

    If it was defined that it needed to be the first thing in a file following whitespace, I think i’f be fine with it.

  14. @funkylab it’s really to do with it not being standardised more than anything else. Like what is the expectation of preprocessing the following file lol.h

    #ifndef foo
    #define foo
    #else
    #pragma once
    #endif
    #include "lol.h"
    Yo

    Is it a single “Yo” or two lines of “Yo”?

    If it was defined that it needed to be the first thing in a file following whitespace, I think i’f be fine with it.