wasted my 30 minutes by calling sizeof() instead of strlen(). Daamn !!

  • 9
    sizeof isn’t really called; it’s a compiler directive not a function
  • 1
    @FrodoSwaggins oh ... just realized that... immature me !!
  • 2
    @FrodoSwaggins That was the most "It's GNU/ Linux, not Linux!" thing I have ever read.
  • 4
    @AlgoRythm if by that you mean absolutely right then yeah I guess so.

    sizeof can only work the way it does at compile time with information that is not written into the program. That’s just a fact, and has been as long as C has existed.

    sizeof is not a function. It does not run at runtime, it does not generate code, it compiles to a literal constant.
  • 1
    @FrodoSwaggins NEEEEEEEEEERD

    Doesn't matter. Nothing is really "called" because c doesn't run, asm does.

    If you really wanted to be anal about something that doesn't matter, you could say it's not callable because it's an operator.
  • 1
    @iamavalos Proceed
  • 4
    @iamavalos You made me actually laugh out loud.
  • 1
    @AlgoRythm C/C++ are meant to be baremetal anyway and require a lot of familiarity with the system to use properly, why would you object to an absolutely valid correction? There are billions of tiny details that the language depends on, the more you know the better.

    sizeof() being a compile time only thing does matter, both when judging the runtime cost and output size of a program and when using sizeof() in compile time computations or in C++ template metaprogramming. It might also trip someone up if they try to use sizeof() like a runtime function by eg. trying function pointer stuff with it.
  • 3


    because the rant uses "call" as a replacement for "use".

    "by using sizeof instead of strlen"

    The correction is unnecessary, and reminds me of all those anal asshats that unironically do the GNU/Linux meme
  • 1
    @AlgoRythm I see your point, but then one could argue that your reaction is a bit extreme too.

    Anyway, I think all points have been made, don't want to let this spiral. Have a good day man, hope whatever you're working on (the C++ UI library?) goes well :)
  • 2
    @AlgoRythm that’s false. Function calls in c have a specific meaning and translate a certain way into assembly code so that they are compatible across object files and compilers, also dynamic libraries. So “calling a function” in c generates a call in assembly according to your os and platforms calling convention. Sizeof does not because it’s not a function. It collapses to a constant.

    This is actually a massive distinction, I know you don’t think it’s a big deal but it kind of is in C land.
  • 1
    OMG, I seem to trigger a debate in an serious topic. By accident I came to know about deeper stuffs. Much glad. Thank you :)
  • 1
Your Job Suck?
Get a Better Job
Add Comment