how to properly use C

>Avoid complex flow constructs, such as goto and recursion.
>All loops must have fixed bounds. This prevents runaway code.
>Avoid heap memory allocation.
>Restrict functions to a single printed page.
>Use a minimum of two runtime assertions per function.
>Restrict the scope of data to the smallest possible.
>Check the return value of all non-void functions, or cast to void to indicate the return value is useless.
>Use the preprocessor sparingly.
>Limit pointer use to a single dereference, and do not use function pointers.
>Compile with all possible warnings active; all warnings should then be addressed before release of the software.

CRIME Shirt $21.68

The Kind of Tired That Sleep Won’t Fix Shirt $21.68

CRIME Shirt $21.68

  1. 4 weeks ago
    Anonymous

    Just pay attention.

  2. 4 weeks ago
    Anonymous

    I hate you rust trannies so fricking much

    • 4 weeks ago
      Anonymous

      That's your own personal hell. We didn't designed C.

      • 4 weeks ago
        Anonymous

        >implying C users designed C

    • 4 weeks ago
      Anonymous

      and I hate dumb homosexuals like yourself who doesn't understand anything and seethes like an ineffectual street shitter because you're told you're wrong. Contrarianism is a mind virus and you will never be a competent coder.

  3. 4 weeks ago
    Anonymous

    >Restrict functions to a single printed page.
    Carmack says you’re a homosexual

  4. 4 weeks ago
    Anonymous

    By switching to C++

    • 4 weeks ago
      Anonymous

      modern c++ doesnt have these issues

      Enjoy your dogshit ABI which will never be fixed in the name of assbackward compatibility.

      • 4 weeks ago
        Anonymous

        extern "C"
        problem solved. also rich of you to say that given C doesn't even have a standards defined ABI outside of: "um my compiler generates this code."
        You homosexuals are just privileged that clang and gcc work together to generate mostly the sameish code.

        • 4 weeks ago
          Anonymous

          >extern "C"
          >99.999% of codebase now unusable without writing a shitload of boilerplate

  5. 4 weeks ago
    Anonymous

    Naw how do I do something useful with these moronic restrictions?

    • 4 weeks ago
      Anonymous

      idk, ask NASA. they did

      • 4 weeks ago
        Anonymous

        They only use Photoshop though

        • 4 weeks ago
          Anonymous

          KEK

        • 4 weeks ago
          Anonymous
        • 4 weeks ago
          Anonymous

          Black pilled and bayzed

        • 4 weeks ago
          Anonymous
        • 4 weeks ago
          Anonymous
  6. 4 weeks ago
    Anonymous

    pointer use to a single dereference, and do not use function pointers.
    GUIs with superposing widgets and popups are often stack based (not talking about the call stack here), you pop the stack when closing a popup, it's not possible to do that at compile time

  7. 4 weeks ago
    Anonymous

    modern c++ doesnt have these issues

  8. 4 weeks ago
    Anonymous

    whats the reason for always checking non-void function returns?

    • 4 weeks ago
      Anonymous

      If a function returns anything then presumably it expects you to do something with it, so if you are going to ignore it you need to make it exceedingly clear that you ignored it on purpose and not just because you were being a lazy dickhead. You write this way for software where if you frick up once in the wrong way you immediately delete hundreds of millions of dollars or alternatively kill people.

      • 4 weeks ago
        Anonymous

        I see. so there's no real "technical" reason for this? I don't know much about C, was just wondering if there are situations where the return value somehow leaked or something because it wasn't used.

        • 4 weeks ago
          Anonymous

          Yes, it's not a technical reason, it's a "communicating to other programmers my intention" reason.

      • 4 weeks ago
        Anonymous

        in any normal language you can explicitly throw away the result just by using a discard like this:
        _ = func();
        the compiler can even optimize the call out if it recognizes that the function has no side effects. unfortunately C is not a well designed language

  9. 4 weeks ago
    Anonymous

    >watch eceleb youtube video
    >come to IQfy spewing whatever buzzwords you just learned
    Why does this happen so often?

  10. 4 weeks ago
    Anonymous

    >recursion is complex
    bro

  11. 4 weeks ago
    Anonymous
  12. 4 weeks ago
    Anonymous

    Thanks, but I'm sticking with Rust

  13. 4 weeks ago
    Anonymous

    >>Use a minimum of two runtime assertions per function.
    I always use three for extra safety!

  14. 4 weeks ago
    Anonymous

    https://man.openbsd.org/style

  15. 4 weeks ago
    Anonymous

    the scope of data to the smallest possible.
    Wow, they managed a single good recommendation, and one that conflicts with older C coding styles.

    • 4 weeks ago
      Anonymous

      >conflicts with older C coding styles
      ... and that's a good thing.

    • 4 weeks ago
      Anonymous

      >they managed a single good recommendation
      checking return codes and turning on as many warnings as possible are also pretty good

  16. 4 weeks ago
    Anonymous

    Compile with -fanalyze, it gives many useful warnings but also some false positives (e.g. if you declare a pointer and assign it to an element of a hashtable in a delete_element function it complains if you don't set it to NULL even though it's only ever used locally)

  17. 4 weeks ago
    Anonymous
  18. 4 weeks ago
    Anonymous

    >runtime assertions

  19. 4 weeks ago
    Anonymous

    function pointers are useful for plugins

  20. 4 weeks ago
    Anonymous

    I guess you have never programmed anything more complex than a fizzbuzz.

  21. 4 weeks ago
    Anonymous

    complex flow constructs, such as goto and recursion.
    Definitely avoid recursion, fricking forbid it. If you can prove that no stack crash happens when using a recursive function, you can also rewrite it to be non-recursive. Goto is closer to the hardware, as in asm jumps, but fricks a bit with C's flow control paradigm. There's nothing inherently wrong with it on a technical level (on the contrary; it is more accurate), it's a style guide directive.
    >>All loops must have fixed bounds. This prevents runaway code.
    while (0x1) {do_iter_setup(); if (breakCondition) break; iter_loop();}

    That's replacing while (0x1) with a fail-safe counter.
    You *shouldn't* require it, but I understand if you want it nonetheless.
    Technically, It is voodoo chicken coding though.
    heap memory allocation.
    As much as you can, definitely.
    functions to a single printed page.
    Some functions are just big, I ask myself, what is the plausibility of refactoring it into subfunctions?
    If you don't use them anywhere else except for in that one big function, it is more structurally correct these are kept in the big function than declared as subfunctions. Again, it is a style guide, nothing technically wrong with not doing it or doing it.
    >>Use a minimum of two runtime assertions per function.
    Style.
    the scope of data to the smallest possible.
    Yes.
    the return value of all non-void functions, or cast to void to indicate the return value is useless.
    Cast to void should be assumed to be the default.
    In the days of no autocomplete, where the IDE couldn't tell you if a function even returns, an explicit cast to void made it obvious to the programmer that the function even has a return value at all.

    • 4 weeks ago
      Anonymous

      >>Use the preprocessor sparingly.
      Let's say you have a variable, it is compile time known if it's unsigned or signed, but you want to keep the option open to the last second which it'll be. So you write code for both. If you use a static const varIsUnsigned = 0x1; and runtime write the code in C, the non-used case will be optimized away, which is exactly the same as manually doing it by preprocessor directive.
      What, exactly, is the limit here?
      Am I using the preprocessor "sparingly" if I instead write the code as seemingly runtime?
      Does that not instead bloat up the runtime part of the code?
      pointer use to a single dereference
      So does that mean only ever using one level of pointer redirection? Because if I want the data from an int**, I will need to dereference twice, intermediary pointer created or not.
      >>and do not use function pointers.
      In non-generalized tasks, it's easy to avoid function pointers, I'm currently trying to write a general PLC OS for the ATmega328 and without function pointers, making tasks/processes would be much, much more cumbersome, like a whole magnitude more.
      with all possible warnings active; all warnings should then be addressed before release of the software.
      Absolutely.

    • 4 weeks ago
      Anonymous

      >>Use the preprocessor sparingly.
      Let's say you have a variable, it is compile time known if it's unsigned or signed, but you want to keep the option open to the last second which it'll be. So you write code for both. If you use a static const varIsUnsigned = 0x1; and runtime write the code in C, the non-used case will be optimized away, which is exactly the same as manually doing it by preprocessor directive.
      What, exactly, is the limit here?
      Am I using the preprocessor "sparingly" if I instead write the code as seemingly runtime?
      Does that not instead bloat up the runtime part of the code?
      pointer use to a single dereference
      So does that mean only ever using one level of pointer redirection? Because if I want the data from an int**, I will need to dereference twice, intermediary pointer created or not.
      >>and do not use function pointers.
      In non-generalized tasks, it's easy to avoid function pointers, I'm currently trying to write a general PLC OS for the ATmega328 and without function pointers, making tasks/processes would be much, much more cumbersome, like a whole magnitude more.
      with all possible warnings active; all warnings should then be addressed before release of the software.
      Absolutely.

      regarding the preprocessor thing you could have just used a typedef in that case

      in general you'll notice that most of these rules are vague and are not phrased in an absolute way: "avoid", "limit", "use sparingly", etc
      the idea is that of course you'll find cases where breaking them is justified but those cases need to be thought about. basically they're implying that if someone's constantly breaking these rules something's up

      in general i agree with all the rules except the on related to function length tbh, just have the amount of assertions be proportional to the size of the function.

      • 4 weeks ago
        Anonymous

        >typedef in that case
        Not if the code requires different algorithms for different typedefs.
        Ok, replace unsigned/signed with sensor A/B, only one sensor will be installed, but both have two different data sets (let's say one does BCD, one binary data output) and you need to write the code for both of them and selectively disable one or the other at final compilation.
        There's a point where typedefs can't help anymore and it's either static const int gType and switch (gType) or #if defined(TYPE) && (TYPE == XYZ), but both are the same when it's compiled down to assembly.
        >amount of assertions
        Correcting myself: Not style, vodoo chicken.
        You should know all possible input data and know what the function maps to each input.
        If I have one U32 input value, there are a finite set of inputs (positive or zero integer number from 0 to 2^32-1) and I can assert each maps to a valid output value.
        Maybe I'm just doing it manually in my head instead of writing it down, I've never used assertions, lol.

        • 4 weeks ago
          Anonymous

          >static const int gType and switch (gType)
          Or use an enum, but that's just syntactic sugar, and (in my opinion) an abonimable amalgamation of C and preprocessor intentions, I avoid them.

  22. 4 weeks ago
    Anonymous

    nobody ever has told you to avoid recursion.

  23. 4 weeks ago
    Anonymous

    >goto is le bad because my CS teacher said so
    Why are academic homosexuals like this?

  24. 4 weeks ago
    Anonymous

    >>do not use function pointers
    >don't use one of the best features
    >don't build anything of consequence
    ok moron

  25. 4 weeks ago
    Anonymous

    >Avoid heap memory allocation
    Good luck writing anything nontrivial.

  26. 4 weeks ago
    Anonymous

    with all possible warnings active; all warnings should then be addressed before release of the software.
    I will use -Wno-incompatible-pointer-types and the compiler will build it. You will warn no one and be happy. Eat ze bugs.

  27. 4 weeks ago
    Anonymous

    >Avoid complex flow constructs, such as goto and recursion.
    goto for cleanup code is fine. it's just a jump instruction. recursion can always be changed to iteration, but sometimes proven tail recursion just looks better. judge the complexity of generated assembly before going for one or the other.
    >All loops must have fixed bounds. This prevents runaway code.
    bullshit. sometimes you need to iterate over linked list.
    >Avoid heap memory allocation.
    bullshit. just deal with failure. avoid vlas for c99+
    >Restrict functions to a single printed page.
    good luck with that. restrict written to code to 80 columns instead of begging for more and better monitors.
    >Use a minimum of two runtime assertions per function.
    fine for public api. stupid for static fns. all arguments passed to internal funcitons should've already been validated.
    >Restrict the scope of data to the smallest possible.
    yep. use curly braces for code blocks often. compilers can take the hint to reuse registers more instead of using the stack.
    >Check the return value of all non-void functions, or cast to void to indicate the return value is useless.
    checking in itself is worthless unless you actually are able to deal with any failure. castsing to void is good code documentation.
    >Use the preprocessor sparingly.
    bullshit. preprocessor balck magic is fine as long as you test your shit. container_of is preprocessor black magic and used everywhere.
    >Limit pointer use to a single dereference, and do not use function pointers.
    frick this. function pointers are awesome and can simplify a lot of stuff. it's best to always typedef function pointer types though.
    >Compile with all possible warnings active; all warnings should then be addressed before release of the software.
    remember that both clang and gcc have ways to disable some warnings for a code block. this will be needed for embeddeds.

    what i'd add:
    - single return statement, works best with goto for cleanup
    - use doxygen comments everywhere

    • 4 weeks ago
      Anonymous

      >bullshit. just deal with failure. avoid vlas for c99+
      Most of this stuff was written with Mars rover's and space probes in mind, i.e. embedded, I think:
      >NASA C Style Guide (1994) SEL-94-003
      https://ntrs.nasa.gov/api/citations/19950022400/downloads/19950022400.pdf
      Or were they using Ada, COBOL or Fortran for them?

      I also have the
      >NASA Manager's Handbook for Software Development Rev. 1 (1990) SEL-84-101
      https://sw-eng.larc.nasa.gov/wp-content/uploads/sites/23/2013/05/Managers-Handbook1.pdf
      saved to disk, maybe some of this is in there as well.

      • 4 weeks ago
        Anonymous

        with embeddeds you likely don't use glibc, and hard assert all alloc family calls. or even don't use libc at all. basically all you need from libc in embedded environment is memcmp, memset, memcpy and that you can easily write yourself, optimized for the platform you're using (like no unaligned access possible, etc.)

        • 4 weeks ago
          Anonymous

          Yeah, I am wondering about how to allocate on the AVR.
          No such thing as a heap allocated, I'm guessing?
          I've avoided them on embedded so far, but now I'm doing something generalized wherein I want the user to decide what the device does and this and this much memory is available for all the tasks.
          >tldr
          Basically, I'm wondering if I have to write my own malloc(), a simple "malloc" and "arduino" search links me to forums, not documentation, so I'm thinking the answer will be yes.
          >memcmp, memset, memcpy
          I do. I was wondering if it's really worth it, it just saves declaring an iterator, but it is, yeah.

  28. 4 weeks ago
    Anonymous

    How do I get good at C? I can do basic shit like program up tries, merge sort. Where do I go from here?

    • 4 weeks ago
      Anonymous

      Find an application where either being extremely low level (e.g. embedded) or extremely fast (e.g. video processing*) pays off.
      I personally love embedded, because I like interfacing from physical reality to digital virtuality and vice-versa.

      *If you know how to use ffmpeg, there are filters that can be run on the GPU. You can pass custom OpenCL code (a C "dialect") to the GPU that executes a 'kernel' (function) on each pixel which is run in parallel for all video pixels of the input video(s). ffmpeg's base selection of OpenCL kernels was extremely lacking, I did one quick one for bit-shifted scaling down and cropping, but that stuck in my mind as something worth checking out. Plus you learn OpenCL.

      • 4 weeks ago
        Anonymous

        >ffmpeg's base selection of OpenCL kernels was extremely lacking,
        https://ffmpeg.org/ffmpeg-filters.html#OpenCL-Video-Filters
        There seem to be quite a few (now?).
        I'm not seeing a hardware scale on any interface now, either, but I definitely remember Vulkan or NVENC having one.
        Scaling can definitely benefit from parallelization, particularly if more complex resampling algorithms are used.

  29. 4 weeks ago
    Anonymous

    [...]

    Arguing with (JPL!) NASA's "reliable" software programming practices does not necessarily imply one to be a midwit fizzbuzzer.
    Let's also clarify that it's NASA's division of Jet Propulsion Laboratory at hand here, so we are most likely dealing with embedded code plus the interfacing software on desktop or server or host systems, not shitty webdev or sysadmin scripting.
    On the contrary, you can argue two C sources, one violating and one conformant, can produce identical ASM output, effectively rendering whatever is declared as a rule as a suggestion, because it is not complete enough a definition to constitute a rule.
    Suck it, Holzmann.

    • 4 weeks ago
      Anonymous

      If NASA were serious about this and not just intellectually jerking off their "oh-my-God-we-go-to-space" jizz everywhere, they'd make their own C compiler that errors out where others warn.

      • 4 weeks ago
        Anonymous

        You can just use a flag to treat warnings as errors. Lot of software uses it for release builds to force any warnings to be fixed or explicitly silenced

        • 4 weeks ago
          Anonymous

          Cool, thanks.
          GCC has, like, 5 billion options and I've never shipped a space probe, I'll keep that in mind.

    • 4 weeks ago
      Anonymous

      Honestly, when you look at the numbers, how many flighthours satellites, spaceships and rockets have, and compare that to hours driven with Toyota cars on Earth, the only thing you could say about NASA and reliability is that it's statistically insignificant.
      ESPECIALLY considering Toyota's throttle code violated the rules 243 times.
      But still, NASA has rare cool engineering edge cases, exotic tech, high stakes, minimal tolerance for error, but, of course, overbearing safety.
      Yeah, yeah, we get why.
      8.4/10, would job, sure.

    • 4 weeks ago
      Anonymous

      >On the contrary, you can argue two C sources, one violating and one conformant, can produce identical ASM output, effectively rendering whatever is declared as a rule as a suggestion, because it is not complete enough a definition to constitute a rule.
      "Can" != "always." To render a rule a suggestion the rule could never result in different ASM vs. not using the rule.

  30. 4 weeks ago
    Anonymous

    Ugh guys wtf do I do here.

    • 4 weeks ago
      Anonymous

      I'd substruct angle and unit, so you reference them by e.g. angle.deg and angle.rad.
      >heap allocation
      You pass an uninitialized statically declared class as an input and configure and initiliaze that.
      Not allocating on the heap has the comfort of saying
      >FRICK YOU GIVE ME WHAT I READ AND WHERE I WRITE
      to whoever needs to implement the function, whereas the function writer can just write it knowing it must correctly be allocated for the function.

      • 4 weeks ago
        Anonymous

        >to whoever needs to implement the function, whereas the function writer can just write it knowing it must correctly be allocated for the function.
        I mean, from that it's basically clear why you just use structs as containers for objects and then pass these to a function set you've written that are basically class methods, in C, because it's more versatile to be used for both dynamic and static allocation.
        Using C++ with complex classes, and by that I mean any class with a size that is runtime/initialization dependent, without using the heap is a nightmare that makes using pure C preferable.

    • 4 weeks ago
      Anonymous

      you have a primary constructor so you MUST call it from every other constructor. do this
      public RotationVector() : this()
      {
      this.calcVector(0);
      }

  31. 4 weeks ago
    Anonymous

    [...]

    >Avoid complex flow constructs, such as goto and recursion.
    No wonder why they never go back to the moon.

  32. 4 weeks ago
    Anonymous

    >how to properly use C
    just don't use it.
    Rust and C++ are rich enough to not be totally worthless. You only use C because it's so basic, it's hard to be hugely surprised by weird LLVM/GCC bugs.

  33. 4 weeks ago
    Anonymous

    That's not how to properly use C. That's how NASA wants you to use C because they have to be hyper vigilant about any possible state which could disable a deep space probe.
    https://en.wikipedia.org/wiki/The_Power_of_10:_Rules_for_Developing_Safety-Critical_Code

    >Avoid complex flow constructs, such as goto and recursion.
    Recursion is fine so long as you know you're not going to blow the stack.
    >All loops must have fixed bounds. This prevents runaway code.
    I would guess they mean a hard constant. I'm fine with the bounds being dynamically determined at runtime.
    >Avoid heap memory allocation.
    LOL no, though I understand why for deep space shit.
    >Restrict functions to a single printed page.
    Maybe a little more, but yeah.
    >Use a minimum of two runtime assertions per function.
    >Restrict the scope of data to the smallest possible.
    >Check the return value of all non-void functions, or cast to void to indicate the return value is useless.
    >Use the preprocessor sparingly.
    Mostly OK.
    >Limit pointer use to a single dereference, and do not use function pointers.
    Understandable on deep space shit, bad advice here on Earth.
    >Compile with all possible warnings active; all warnings should then be addressed before release of the software.
    That should apply to everything on the planet, but it does not.

    • 4 weeks ago
      Anonymous

      >LOL no, though I understand why for deep space shit.
      Unironically that's the only good thing on the list. The heap is a slow piece of shit and you should limit your interactions with it. Allocate a huge block and work with that block. Do not allocate memory for individual "objects". Do not deallocate individual "objects". Allocate as a stack and when you're done with it, reset your stack for the next tick. This isn't so much about keeping your code simple as it is keeping your code fast.

      >but what about situation XYZ where i need to reallocat-
      No. Avoid constructs and "solutions" that require reallocation in the first place.

      • 4 weeks ago
        Anonymous

        >Unironically that's the only good thing on the list. The heap is a slow piece of shit and you should limit your interactions with it. Allocate a huge block and work with that block. Do not allocate memory for individual "objects". Do not deallocate individual "objects".
        NASA's rule doesn't allow you to use the heap at all except for one big block at startup. I agree with your point that the heap is slow relative to direct programmer management of a large block, assuming a qualified programmer. (Remember that pointers make most people cry at night.) But it's fine to have some heap interaction during the life of the program.

  34. 4 weeks ago
    Anonymous

    >guide on how to properly use C
    >not a single mention of static analyzer and sanitizers
    use cppcheck
    use sanitizers
    other languages have these included whereas it's opt-in for C and C++, don't be a mouthbreather and use the fricking tools at your disposition.

  35. 4 weeks ago
    Anonymous

    > Avoid goto because reasons

    Goto is extremely useful for some things like making a goto chain of handler cases work like exceptions and breaking from nested loops. I dgaf what Dijkstra says.

    • 4 weeks ago
      Anonymous

      This. Goto shouldn't be you go to for programming but it's damn useful for those peculiar situations where you're encountering odd behavior in a nested loop or some other hangup

    • 4 weeks ago
      Anonymous

      Dijkstra is taken out of content. The goto he was complaining about was one which could jump to anywhere in the entire program. He probably would not have any issue with the limited goto of C.

      • 4 weeks ago
        Anonymous

        longjmp considered harmful

        • 4 weeks ago
          Anonymous

          nta, but it should
          once you do c you do heresy anyways
          calling it "bad, dontouch" just delays the inevitable until youknow whatswhat and you can appreciate clean code
          so that you use it sparsely w/o a supervisor reading all your code or truly stringent norms
          i think

          otherwise i would 100% use longjump if i were to write a language in C.
          like, use long jumps instead of pointers to functions
          dono yet how it would translate into cache, tho...

        • 4 weeks ago
          Anonymous

          await considered harmful

        • 4 weeks ago
          Anonymous

          I've seen longjmp() used correctly a few times in my career. It's a piece of rarely-needed awfulness, but when you need it, you REALLY need it and have no other alternative.

  36. 4 weeks ago
    Anonymous

    why do trannies hate C so much? if you don't like it, don't use it.

    • 4 weeks ago
      Anonymous

      the same reason why they decide to be trannies

  37. 4 weeks ago
    Anonymous

    >recursion
    You should never use recursion in C. That just sounds like a formula to get a stack overflow.
    >all loops have fixed bounds
    This is OK generally, but in practice a lot of loops won't because they are dependent on a user to change state. I wouldn't want my program to just randomly stop while I was using it because you put a fixed bound on the window loop.
    >avoid heap
    I would just say use stack memory first and have a structure to organize memory you allocate on the heap.
    >assertions
    Assert when necessary. If you fail an assertion your program crashes. I would say only use assert when your program can't continue if the assertion is false. If you can recover just use a guard statement.
    >limit pointer to a single dereference
    A stupid arbitrary rule. You may need to modify the data pointed at several different times. If you could do this you would just be better allocating it on the stack. Heap lifetimes kind of make it so you are going to be using that memory more than just once.

  38. 4 weeks ago
    Anonymous

    >>All loops must have fixed bounds. This prevents runaway code.
    pointer use to a single dereference, and do not use function pointers.
    could have just said "don't develop anything non-trivial"

    >cast to void to indicate the return value is useless.
    pointless busywork

    with all possible warnings active; all warnings should then be addressed before release of the software.
    if I wanted an overbearing compiler to disallow 90% of reasonable code based on shallow rules and surface level assumptions I'd just use rust

    rest is fine though

  39. 4 weeks ago
    Anonymous

    some of these only make sense in hard realtime systems
    >unbounded loops
    >avoid heap allocations
    not many people on IQfy probably know what I'm even talking about

  40. 4 weeks ago
    f

    >don't use a hammer when a screwdriver would work better
    >don't use 5 nails when 2 would do the job
    >keep it simple stupid
    Truely C is a dead language and any alleged "programmers" still using it should be studied for the sake of science.

    • 4 weeks ago
      Anonymous

      >out runs your code while saving electricity
      What did slower languages mean by this?

      • 4 weeks ago
        Anonymous

        >sepples 56% slower than C
        >ada 85% slower than C
        based contrived benchmarks

        • 4 weeks ago
          Anonymous

          > makes up numbers
          > "I win!"

          >can't handle facts
          >pretends facts don't exist

          • 4 weeks ago
            Anonymous

            Next time, before making such a claim, make sure that you have in fact sent a single fact and not, for instance, a table of numbers next to programming languages.

          • 4 weeks ago
            Anonymous

            >a table of numbers next to programming languages
            seems a concise way to summarize facts, no?

          • 4 weeks ago
            Anonymous

            C 34
            C++ 5.56
            PHP 23
            Java 47
            Lisp 1

            What now white boy?

          • 4 weeks ago
            Anonymous

            >no source

          • 4 weeks ago
            Anonymous

            Do you have a source on that?
            Source?
            A source. I need a source.
            Sorry, I mean I need a source that explicitly states your argument. This is just tangential to the discussion.
            No, you can't make inferences and observations from the sources you've gathered. Any additional comments from you MUST be a subset of the information from the sources you've gathered.

          • 4 weeks ago
            Anonymous

            >reddit memes
            You have to go back.

            The difference between

            >out runs your code while saving electricity
            What did slower languages mean by this?

            and

            C 34
            C++ 5.56
            PHP 23
            Java 47
            Lisp 1

            What now white boy?

            is that the latter is literally made up and the former was the result of a study:
            https://thenewstack.io/which-programming-languages-use-the-least-electricity/

            Now, you can debate the parameters of the study. But it is a study. People tried to fairly determine energy use and performance. So that table is closer to the truth than some might care to admit.

          • 4 weeks ago
            Anonymous

            >https://thenewstack.io/which-programming-languages-use-the-least-electricity/
            I don't care how the article words it
            TOTAL C VICTORY ACCROSS THE BOARD

            That being said, try making a website front-end in C and see how far that'll get you...

          • 4 weeks ago
            Anonymous

            >TOTAL C VICTORY ACCROSS THE BOARD
            Based and C Victory pilled.

          • 4 weeks ago
            Anonymous

            >That being said, try making a website front-end in C and see how far that'll get you...
            That makes no sense, a website frontend is by definition not made in C.
            >That being said, try making a brick house out of wood and see how far that'll get you

          • 4 weeks ago
            Anonymous

            Use C to backend HTML front-end.
            Been there, done that too.
            (Never again. HTML/CSS/JS for front-end, but backend would still do C 10/10 everytime.)

          • 4 weeks ago
            Anonymous

            Use C to backend HTML front-end.
            Been there, done that too.
            (Never again. HTML/CSS/JS for front-end, but backend would still do C 10/10 everytime.)

            *One could design a new http(s) protocol or "HTML" format, i.e. one that doesn't use ASCII tags to render webpages, but bits and bytes.
            Then you could probably do some pretty cool stuff on the web-front-end.
            Not sure if WASM fits this description, I've never *really* looked into it, and I've heard both good and bad things about it.

            I mean, on a technical level, any modern multiplayer game fulfils the criteria, but it of course needs to be standardized to be able to use a game-engine as the browser for a new type of web (internet?).

          • 4 weeks ago
            Anonymous

            There have been binary HTTP extensions, and there are binary page descriptions possible (PDF if nothing else!) WASM is just another way of deploying (most of) a page as an application. But standard HTTP and HTML+CSS+JS are what's won... for now.
            With compression and encryption, so what goes on the wire isn't actually plain text.

          • 4 weeks ago
            Anonymous

            That's true.
            I mean, the web itself isn't too bad.
            It's just being coded by people who are not so stringent in their code and the web that serves this code is quite forgiving towards bad code.

            Meanwhile, C programmers write firmwares that can kill and maim people and take down entire city blocks, sometimes with the intent prevent that, and sometimes even with the explicit intent of the contrary.
            Fortunately, C isn't as forgiving and bugs are often spotted immediately or intermediately, or, unfortunately, lie dormant, sometimes for decades.
            Everyone barely gets enough time to ship, everyone's deadline was always yesterday, and things are never perfect. That won't change with Rust, or with any other language, it's just a waste of time.

            Long story short, if you code and the worst that can happen is a box is misaligned, you won't even try to push yourself to write real good and proper code.
            If you end up in jail because of negligence, that's a whole other bag.

          • 4 weeks ago
            Anonymous

            The entire web stack was a mistake. Tim Berners-Lee just wanted easy to view and edit papers on the Internet, with hyperlinks and pictures. His choices make sense in that context, but are shit for what the web grew into.

          • 4 weeks ago
            Anonymous

            >The entire web stack was a mistake.
            Especially JS.

      • 4 weeks ago
        Anonymous

        > makes up numbers
        > "I win!"

  41. 4 weeks ago
    Anonymous

    >Restrict functions to a single printed page.
    everything except this is true, a million nested functions does not make a program easier to read.

    • 4 weeks ago
      Anonymous

      It literally does. And while I think max length should be a bit longer, programmers who stuff a book in a single function get the rope.

      • 4 weeks ago
        Anonymous

        Books are simple because you read them from start to finish.
        I've never thought "wow this would be so much more clear if I had to constantly jump back and forth between pages."

        • 4 weeks ago
          Anonymous

          lots of books are designed that way though, key example being textbooks that constantly refer to prior and later pages.

  42. 4 weeks ago
    Anonymous

    uhm sweety you should use Rust

  43. 4 weeks ago
    Anonymous

    >and do not use function pointers
    >can no longer have a user installable callback from an IRQ Handler

    • 4 weeks ago
      Anonymous

      >deep space probes
      >”users”

    • 4 weeks ago
      Anonymous

      Use an event loop instead. This avoids having to write interrupt-safe code.

  44. 4 weeks ago
    Anonymous

    [...]

    found the nocoder.
    theres 99.99999% chances you wont be coding a probe thats somewhere around mars.
    also...
    < current day academic community

    https://i.imgur.com/2phRRHN.png

    >Avoid complex flow constructs, such as goto and recursion.
    >All loops must have fixed bounds. This prevents runaway code.
    >Avoid heap memory allocation.
    >Restrict functions to a single printed page.
    >Use a minimum of two runtime assertions per function.
    >Restrict the scope of data to the smallest possible.
    >Check the return value of all non-void functions, or cast to void to indicate the return value is useless.
    >Use the preprocessor sparingly.
    >Limit pointer use to a single dereference, and do not use function pointers.
    >Compile with all possible warnings active; all warnings should then be addressed before release of the software.

    lol
    yeah, if you code for probes to be sent to mars, and you cant sigabort an infinite loop.
    good luck getting anything done anywhere else with such constraints, doe

    • 4 weeks ago
      Anonymous

      I see you're an expert on sending probes to orbit Mars

      • 4 weeks ago
        Anonymous

        no, its the literal reason why you have limited loops.
        i dont remember where i read it, but i believe the rationales for the measures are included in the norm/guideline document itself...
        bc yes, i heard about nasa norms, and yes, obviously i got interested in em...

    • 4 weeks ago
      Anonymous

      DEI did not cause the replication crisis. have a nice day for making me defend leftist ideology.

      • 4 weeks ago
        Anonymous

        No, but it accelerated it.

      • 4 weeks ago
        Anonymous

        youre right
        but thats not what im saying doe

        theres a couple ways you can interpret the meme

        the actual true culprit is white,no?
        like who did i give solid evidence against in this meme?
        the black girl?
        nah,for her the critique is that she doesnt take her job seriously

        the white girl doe
        and thelast lines:
        "(2005) - why most research is fake"

        its not abt race
        race is bate for low iq topropagate the meme
        high iq message is:
        science is corruptible, and thus it was corrupted
        and its nothing new, bc its a clearproblem since...
        *looks at watch*
        19 years?

      • 4 weeks ago
        Anonymous

        >19 years
        how old are you, anon?
        im friggin curious

        • 4 weeks ago
          Anonymous

          I've seen zoomers who think DEI started in the 20th century, so it's a reasonable assumption of idiocy.

          • 4 weeks ago
            Anonymous

            >idiocy
            theyre rootless

            no transfer of trans-generational (historical) knowledge
            no transfer of trans-generational wealth

            rootless.
            for the bettermentofbig corpo

          • 4 weeks ago
            Anonymous

            >idiocy
            theyre rootless

            no transfer of trans-generational (historical) knowledge
            no transfer of trans-generational wealth

            rootless.
            for the bettermentofbig corpo

            this is the thing.
            those at the topdont care either way...
            as long as they stay at the top

            this is why politicshas nothing to do with tech.
            bc politicsare opinions
            and as such are subjective
            and as such are not scientificallyprovable

      • 4 weeks ago
        Anonymous

        >19 years
        how old are you, anon?
        im friggin curious

        nah
        srsly
        i didnt mean that in a pejorative way
        datapoint kind of things.
        also autism. coming from drunkenness.
        quite exotic tbqfwy

  45. 4 weeks ago
    Anonymous

    >no goto
    >fixed bound loops
    pick one

    • 4 weeks ago
      Anonymous

      why tho?

  46. 4 weeks ago
    Anonymous

    >Avoid complex flow constructs, such as goto
    topkek

    • 4 weeks ago
      Anonymous

      This is a matter of preference, I think non-goto is more readable, because the indentations line-up.
      There's no objective right or wrong.

    • 4 weeks ago
      Anonymous

      Goto actually can clean up a function. The problem is that the vast majority of developers merely frick it up. It's a filter like pointers and bitmasks. But not enough people pass the filter to write all the code that's needed, so we create languages which do not allow them.

      • 4 weeks ago
        Anonymous

        people struggle with bitmasks? I understand struggling with clever use of bitwise operators, but bitmasks are uber simple.

    • 4 weeks ago
      Anonymous

      int step = 0;
      if ((step++, rc = do_thing1()) ||
      (step++, rc = do_thing2()) ||
      (step++, rc = do_thing3(*~~
      {
      switch (step)
      {
      case 3: cleanup3()
      case 2: cleanup2()
      case 1: cleanup1()
      }
      }

      • 4 weeks ago
        Anonymous

        Either optimized away to the same thing

        >Avoid complex flow constructs, such as goto
        topkek

        would produce (in fact, those both might produce identical output), or slower.
        t. experience

        • 4 weeks ago
          Anonymous

          >optimized away to the same thing longer code produces
          good?
          >or slower.
          what there could possibly be slower? it would have the exact same amount of jumps and the only additional thing it does is increment an int for every step in your function. I guess that would technically make it slower if it wasn't optimised out but why would that ever matter?

          • 4 weeks ago
            Anonymous

            Because you're adding instructions for branches and increments, when it could just be branches.
            It's a compile-time known run count, the compiler will try to unroll it and see if it's better and that would look exactly the same as what was posted above.
            Trust me, been there, done that.

            It's all this leetcode brainrot that makes you think the fastest solution is some nifty way of implementing things, when in C (and ASM) it's in more than 66% of cases just the dumbest possible code that works the fastest.

            I mean, if your goal is to avoid goto, sure, write it like that.
            I find those rules... well, let's just say, I'd argue a lot.
            I'd argue so much, we'd have rules how the output should look like, not the input.

          • 4 weeks ago
            Anonymous

            it optimises the whole thing out at -O1 and above
            https://godbolt.org/z/5bhe5dKcr

          • 4 weeks ago
            Anonymous

            Because you're adding instructions for branches and increments, when it could just be branches.
            It's a compile-time known run count, the compiler will try to unroll it and see if it's better and that would look exactly the same as what was posted above.
            Trust me, been there, done that.

            It's all this leetcode brainrot that makes you think the fastest solution is some nifty way of implementing things, when in C (and ASM) it's in more than 66% of cases just the dumbest possible code that works the fastest.

            I mean, if your goal is to avoid goto, sure, write it like that.
            I find those rules... well, let's just say, I'd argue a lot.
            I'd argue so much, we'd have rules how the output should look like, not the input.

            https://godbolt.org/z/hjseEbbnq
            here's the goto version. It looks like it uses one less jump but that's only because it gets rid of goto error_3 since there's no code being executed in case of success which there would be in actual code. As a matter of fact that would add an extra return.
            if you want to argue that the different structure of the jumps would still affect performance by affecting branch prediction then sure, I can't be fricked actually checking that

          • 4 weeks ago
            Anonymous

            No, I'm saying, they're the same, I'm saying, the loop code is unnecessary (as you can see from the output), why
            a) waste time and effort to write it
            b) confuse other programmers by it
            c) ... what am I missing?

            I'm not sure if we're not actually on the same page or not.

          • 4 weeks ago
            Anonymous

            Thanks.
            Yes, and the ASM is basically jmp here, jmp there, which is what the goto C code is basically doing in

            >Avoid complex flow constructs, such as goto
            topkek

            .
            The if/else cascade (which I subjectively prefer from a syntactical standpoint) will, I'm 99% sure, produce exactly the same assembly code.

            I don't care if or not I can use goto, because the output is the same.
            But on the flipside, code like this can happen

            int step = 0;
            if ((step++, rc = do_thing1()) ||
            (step++, rc = do_thing2()) ||
            (step++, rc = do_thing3(*~~
            {
            switch (step)
            {
            case 3: cleanup3()
            case 2: cleanup2()
            case 1: cleanup1()
            }
            }

            , which works and is not wrong, but can be extremely confusing for other programmers, because the intention of using a loop is superficial, leaving one asking oneself, if the original programmer was just... weird or whether there's something more going on, i.e. goto forbidden.

      • 4 weeks ago
        Anonymous

        Absolutly repulsive. Anyone who creates contortions such as this just to satisfy a religious aversion to goto should never be permitted to touch a computer ever again.

        • 4 weeks ago
          Anonymous

          I know, I just wanted to demonstrate that it's possible to eliminate goto without adding a level of indentation for every step, which is imo even more repulsive

          No, I'm saying, they're the same, I'm saying, the loop code is unnecessary (as you can see from the output), why
          a) waste time and effort to write it
          b) confuse other programmers by it
          c) ... what am I missing?

          I'm not sure if we're not actually on the same page or not.

          I didn't think it was that confusing personally, not that I'd actually use it, but I see your point. Also there's no loop there, just a short circuiting conditional. I think it might actually be a bit clearer with a loop honestly

          int step, rc = 0;
          for (step = 1; !rc; step++)
          {
          switch (step)
          {
          case 1: rc = do_thing1(); break;
          case 2: rc = do_thing2(); break;
          case 3: rc = do_thing3(); break;
          }
          }

          switch (step)
          {
          case 3: cleanup3();
          case 2: cleanup2();
          case 1: cleanup1();
          }

          still not exactly pretty

          • 4 weeks ago
            Anonymous

            you know what, let's make it even worse
            int step, rc = 0;
            for (step = 0; !rc; step++)
            (int (*)())[]{ do_thing1, do_thing2, do_thing3 }[step]();

            not gonna check if that compiles cause I don't want my compiler to know I would write code like that

          • 4 weeks ago
            Anonymous

            I think you need to declare a static const array with the values being the function pointers beforehand, C doesn't like immediate declarations for things that aren't primitives...
            But otherwise, yeah, that would work.
            (and probably optimized away again, lul)

          • 4 weeks ago
            Anonymous

            I'm sure GCC would let you do it tbh
            for (step = 0; !(rc = (int (*)())[]{ do_thing1, do_thing2, do_thing3 }[step]()); step++);

      • 4 weeks ago
        Anonymous

        >cnilecucks invent this just to avoid using C++ that would compile down to equivalent code

  47. 4 weeks ago
    Anonymous

    whenever i see someone like OP publicly flapping off at the mouth with all these dogmatic rules about "how to properly write code" i immediately peg them as a young clueless novice who hasn't written anything in their lives and their real passion is blogging/trolling/attention seeking behavior rather than doing anything actually productive with their time. on the bright side, there is a good chance that they have very low self esteem and will end up killing themselves at some point and thereby sparing us all from any further exposure to their various annoying personality disorders.

  48. 4 weeks ago
    Anonymous

    >All loops must have fixed bounds
    While loops are fine so long as you can prove the condition will become false eventually and within a certain upper bound in time. There are cases where putting a fixed iteration limit actually makes the code more wasteful, since you'd be running more loops than needed, or more complicated since you'd need a break statement encapsulated in a conditional, or some kind of weird multi-parameter Boolean evaluation that's much harder to decode. Just don't be a fricking moron, and check the convergence of your algorithm.
    >This prevents runaway code
    If your program's logic allows a loop to run forever, you need to fix the logic, not impose artificial restrictions like loop count limits. Even implementing a check for a runaway condition and terminating is better than this.

    • 4 weeks ago
      Anonymous

      >check the convergence of your algorithm
      or be explicitly aware that you're using one without a known upper bound; sometimes that's all you've got so that's what you gotta do, but it isn't usual in safety critical software
      also, some programs use unbounded looping for other reasons, such as the loop that handles client connections in a socket server, and that's when you want to prove that you only have one unbounded loop
      in real safety critical software, you're probably running periodically on a timer

      • 4 weeks ago
        Anonymous

        >in real safety critical software, you're probably running periodically on a timer
        this makes alot of sense
        >what can go wrong if you re-init from rom every n cycles?
        rom should be more resileient than ram,no?
        like, woven memory...

  49. 4 weeks ago
    Anonymous

    Nocoder.

  50. 4 weeks ago
    Anonymous

    >avoid goto
    Stopped reading there
    You are a gay OP

  51. 4 weeks ago
    Anonymous

    >>Use the preprocessor sparingly.
    Why'd they have to include this one?

  52. 4 weeks ago
    Anonymous

    Why does no one use C for anything now days beyond programing dildos and making LED flash different colors? Is it really that shit or is a generational skill issue?

    • 4 weeks ago
      Anonymous

      I thought the dildo meme was rust

    • 4 weeks ago
      Anonymous

      What are you talking about? Every non-hobbyist operating system kernel I can think of is written in C.

      • 4 weeks ago
        Anonymous

        Nothing new (the past 30 years) has been made in C.

    • 4 weeks ago
      Anonymous

      It's not shit, it's a good baby's first systems programming language. But one day everyone has to outgrow their hotwheels bed.

    • 4 weeks ago
      Anonymous

      There are just too few C programmers and too many dildos out there, man...
      It's also weird when we venture out into other fields where C once used to be common, like relics of a former past or masters of a lost and forgotten art.
      The web used to have a lot of F/CGI servers running C programs that served web pages.
      Nowadays, only nerds do that on their personal blogs where they just code the entire webserver in C to serve port(s) 80/443.
      No "professional" or "corporate" uses C anymore, I think.
      But when you look at the numbers

      >out runs your code while saving electricity
      What did slower languages mean by this?

      and see that C uses 1/30th of the energy that PHP uses, it could be worth the effort to return to the former glory days of C on the web if cutting down datacenter energy consumption by 97% is a worthwhile investment.
      Don't ask me, I'm busy programming dildos.

    • 4 weeks ago
      Anonymous

      Our fathers made the foundation and we are on our hands and knees trying to crush ants with the palms of our hands like sped kids

  53. 4 weeks ago
    Anonymous

    Let's assume I'm white and I already know the basics of programming. How would you learn C ( as a white man).

    • 4 weeks ago
      Anonymous

      Well, the White Man would've searched the internet for a free and open source IDE with a compiler, found one, downloaded and installed it, and is currently in the process of replacing the default "Hello, World!" message of the included example program with his customized text containing the words "Frick off, you soggy c**t!"

      Truly, nothing to write home about.

      • 4 weeks ago
        Anonymous

        So what you're saying is that white people are only fizzbuzzers and hello world aficionados?

        • 4 weeks ago
          Anonymous

          Yes, of course!
          What else?

          >Well, the White Man would've searched the internet for a free and open source IDE with a compiler, found one, downloaded and installed it
          a White Man would've opened up a text editor and wrote Hello world into hello.c before typing cc hello.c && ./a.out

          Get out of here with your IDE crap, IDEs only increase the level of project complexity that can be stomached and thus incentivize bad code.

          Bla-bla-bla, if you just want to write one simple C program without concerning yourself with the complexity of compiler, that is a valid option.
          Get your no-true-scotsman bullshit outta here.

          • 4 weeks ago
            Anonymous

            >the complexity of compiler
            # cc hello.c
            # ./a.out
            Hello World!

            wow so complex

          • 4 weeks ago
            Anonymous

            He probably meant build systems.

          • 4 weeks ago
            Anonymous

            Why do you need a build system when all C is used for is making a couple of LEDs blink on and off? What's that, like 50 lines of code?

          • 4 weeks ago
            Anonymous

            >all C is used for is making a couple of LEDs blink on and off

          • 4 weeks ago
            Anonymous

            Behold the power of C

            ?t=429

          • 4 weeks ago
            Anonymous

            >some dude uses c to blink lights
            >c is only used to blink lights
            You rode the short bus to school, didn't you?

          • 4 weeks ago
            Anonymous

            what you think your display is anon? (though it's not necessarily LEDs, same principle)

          • 4 weeks ago
            Anonymous

            # ./configure
            # make
            # ./app

            wow so complex

          • 4 weeks ago
            Anonymous

            I can tell you never programmed yourself. That's ok.

            what you think your display is anon? (though it's not necessarily LEDs, same principle)

            Nobody denies that, but

            Why do you need a build system when all C is used for is making a couple of LEDs blink on and off? What's that, like 50 lines of code?

            made it look like that's the sole purpose of C, which is ridiculous.

          • 4 weeks ago
            Anonymous

            >I can tell you never programmed yourself. That's ok.
            I have anon, configuring automake or cmake is trivial compared to a C program complex enough to need it. I just hate IDEs because they're slow, clunky, and incentivize bad code. If your codebase is too complex and unwieldy for you to develop using vim/emacs, then it needs to be refactored into something simpler.

          • 4 weeks ago
            Anonymous

            Segfaulting on mission critical infrastructure isn't a usecase.

          • 4 weeks ago
            Anonymous

            mission critical infrastructure doesn't have such concept as a segmentation fault, moronic Black person

          • 4 weeks ago
            Anonymous

            >configure
            yup it's unnecessarily complex, that's why my makefiles don't have configure step, it's already configured to just work for GNU/Gentoo
            >b-b-but what about what a-ACK!
            Install Gentoo.

      • 4 weeks ago
        Anonymous

        >Well, the White Man would've searched the internet for a free and open source IDE with a compiler, found one, downloaded and installed it
        a White Man would've opened up a text editor and wrote Hello world into hello.c before typing cc hello.c && ./a.out

        Get out of here with your IDE crap, IDEs only increase the level of project complexity that can be stomached and thus incentivize bad code.

        • 4 weeks ago
          Anonymous

          >a white man would write hello world in notepad and call it programming
          This is why jeets are replacing your troony asses.

  54. 4 weeks ago
    Anonymous

    >do not use function pointers
    The virgin "b-but muh multitheading!" vs the chad NASA

  55. 4 weeks ago
    Anonymous

    Compilers and an incompetent standards committee killed C.

    You know it's the truth.

  56. 4 weeks ago
    Anonymous

    [...]

    Why is the "Uses" section in that page just shitting on Toyota

  57. 4 weeks ago
    Anonymous

    >>All loops must have fixed bounds. This prevents runaway code.
    Also prevents you from writing nontrivial programs.

  58. 4 weeks ago
    Anonymous

    >need to branch into several different functions depending on a value
    >have big brain idea
    >decide that instead of passing the value to a switch I’ll use a function pointer to make the code branchless
    >test this against the switch to make sure it’s faster
    >it’s slower

    • 4 weeks ago
      Anonymous

      >your processor totally doesn't need to branch on value of function pointer
      daily babyduck humiliation ritual

      • 4 weeks ago
        Anonymous

        That’s correct, I gave the function the address of the function pointer, so there was no branching

        • 4 weeks ago
          Anonymous

          yes it's all magic, compiler just inlines the function directly, processor doesn't need to fetch the address then fetch the instructions from the address or anything

Your email address will not be published. Required fields are marked *