4 ms·
Great site, but the JSON looks like it's embedded in C as values but is really just a macro that expands it into a string and then parses it. So you can't put a
by hyperhello 2y ago
Great site, but the JSON looks like it's embedded in C as values but is really just a macro that expands it into a string and then parses it. So you can't put any local variables into the JSON.
In my opinion, C really needs some officially supported reflection for the names of enums and such things. People have reinvented the wheel so many times and it never quite gets there.
- immibis 2y agoThat would be a C++ feature. C is very "batteries not included". In particular, it won't generate entire functions or data blocks that you didn't write or include from a library.
- deleted 2y ago[deleted]
- DeathArrow 2y ago>In my opinion, C really needs some officially supported reflection for the names of enums and such things. C is good as it is an someone has the chance to hold all its features in his memory. If you need or want to complicate things, there's C++ or Rust.
- pjmlp 2y agoI very much doubt that as any pub quiz on C will validate. People think they know C, in reality they never read ISO C document, aren't aware of the differences between ISO C standard library and POSIX, how each compiler handles ill formed no diagnostic required, implementation defined and UB parts of the standard, and to top that even better compiler specific extensions.
- virgilp 2y agoYou do not need how compiler handles UB parts of the standard; in fact you should NEVER rely on it, as it can change without warning. That's effectively "incorrect code", by definition.
- pjmlp 2y agoAnd yet that is what many folks happen to do, because "performance all the things!".
- uecker 2y agoThey will also do this in C++ or Rust. The only difference is that in Rust they will pretend it is ok because they wrapped it "unsafe", so if they mess up it is nobody's fault because it can not possible be a problem with Rust or the Rust programmer, so it was unavoidable fate.
- pjmlp 2y agoLike in any language that has adopted unsafe concept since ESPOL/NEWP did it in 1961, at least Rust has the advantage we can find those code blocks without the help of a static analysis tool. Nowdays C++ has inherited the same mentality as many performance minded C developers, which is a bit sad, given that during the 1990's it felt we had a better security first mentality, especially with the vendor specific frameworks that were shipped alongside the compilers. Regarding static analysis tooling it is kind of sad that many developers still think they known better than the language authors themselves, as per Dennis own words, > Although the first edition of K&R described most of the rules that brought C's type structure to its present form, many programs written in the older, more relaxed style persisted, and so did compilers that tolerated it. To encourage people to pay more attention to the official language rules, to detect legal but suspicious constructions, and to help find interface mismatches undetectable with simple mechanisms for separate compilation, Steve Johnson adapted his pcc compiler to produce lint [Johnson 79b], which scanned a set of files and remarked on dubious constructions. -- http://cm.bell-labs.co/who/dmr/chist.html http://cm.bell-labs.co/who/dmr/chist.html And to come back to the original point, the worst part regardless of the language is that most tricks are done due to cargo cult and hearsay, without reaching to a profiler a single time.
- chlorion 2y agoWhat are you even talking about? I've never saw anyone claim that doing UB in Rust is okay because its wrapped in an unsafe block? If anything I've saw the exact opposite of this, cases of UB in libraries is considered a bug almost always, vs in C or C++ where "its the users fault for doing the thing wrong". I notice you spreading an awful lot of bs about rust lately, not sure what the deal is but its pretty childish and lame, not to mention objectively wrong.
- uecker 2y agoSome even don't know that there is no such thing as "ill formed no diagnostic required" in C.
- xnacly 2y agoHi, author here, I just added the JSON macro to omit the quotation escaping around object keys and strings: without JSON macro: char* j = "{ \"key\": [\"value1\", \"value2\"]}"; with JSON macro: char *j = JSON({ "key": ["value1", "value2"]}); But yes of course, due to the stringify no C values can be embedded - i wouldnt even know how one would solve this with a macro, but maybe someone has an idea and can comment on that.