Comment by yipikaya

Comment by yipikaya 3 days ago

9 replies

As an aside, it's amusing that it took 25 years for C coders to embrace the C99 named struct designator feature:

    HttpParser parser = {
        .isValid = true,
        .requestBuffer = strdup(request),
        .requestLength = strlen(request),
        .position = 0,
    };
All the kids are doing it now!
rurban 3 days ago

It's only Microsoft's fault to have not implemented it for decades in MSVC. They stayed at C89 forever.

  • flykespice 3 days ago

    I never understand the reason why Microsoft lagged so much behind on newer c standards adoption. Did their compiler infrastructure made it difficult to adopt newer standards flexible? Or they simply did not care?

    • rurban 3 days ago

      They focused on C++ only. Management, not their devs.

1718627440 3 days ago

This is nice for constant data, but strdup can return NULL here, which is again never checked.

> it took 25 years for C coders to embrace the C99 named struct designator feature

Not sure if this actually true, but this is kind of the feature of C, 20 years old code or compiler is supposed to work just fine, so you just wait for some time to settle things. For fast and shiny, there is Javascript.

davemp 3 days ago

I’m still regularly getting on projects and moving C89 variable declarations from the start of functions to where they’re initialized, but I guess it’s not the kids doing it.

  • 1718627440 2 days ago

    I only declare variables at the begin of a block, not because I would need C89 compatibility, but because I find it clearer to establish the working set of variables upfront. This doesn't restrict me in anyway, because I just start a new block, when I feel the need. I also try to keep the scope of a variable as small as possible.

  • mkfs 3 days ago

    > C89 variable declarations from the start of functions

    Technically it's the start of a block.

    • davemp 3 days ago

      Technically but I don’t think folks ever really bothered.

varjag 3 days ago

Some of the most famous C codebases (e.g. the Linux kernel) been using them for some time.