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!
It's only Microsoft's fault to have not implemented it for decades in MSVC. They stayed at C89 forever.
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?
They focused on C++ only. Management, not their devs.
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.
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.
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.
> C89 variable declarations from the start of functions
Technically it's the start of a block.
Technically but I don’t think folks ever really bothered.
Some of the most famous C codebases (e.g. the Linux kernel) been using them for some time.