Live data from Hacker News

Tell HN: C Experts Panel – Ask us anything about C

news.ycombinator.com

371–380 of 978 posts

Re: Tell HN: C Experts Panel – Ask us anything about C

#371

As there are a lot of C-masters lurking in this thread: How can one process unicode (UTF-8) properly in C? As a CJK person, I wish there was a robust solution. Are there any standardized ways or proposals? (Using wchar doesn't count.)

https://bitbucket.org/knight666/utf8rewind/src/default/

Re: Tell HN: C Experts Panel – Ask us anything about C

#372

When deciding on the behavior of some operation that maps to hardware [1], how do you weight the existing hardware behaviors? For example, if all past, current and contemplated hardware behaves in the same way, I assume that the standard will simply enshrine this behavior. However, what if 99% of hardware behaves one way and 1% another? Do you set the behavior to "undefined" to accommodate the 1%? At what point to yo…

I would say that the committee does pay attention to hardware variations, even when there are no examples of existing hardware that implement a feature (for example, a trap representation for integers other than _Bool). Some of the thinking is that "if it was ever implemented in hardware, it could be again). I'm not crazy about this thinking, and I largely think that language features for which there are no existing…

Some example of hardware variation (since you mentioned shifting and overflow):

- signed integer overflow or division by zero occurs, a division instruction traps on x86, while it silently produces an undefined result on PowerPC - left-shifting a 32-bit one by 32 bits yields 0 on ARM and PowerPC, but 1 on x86; - left-shifting a 32-bit one by 64 bits yields 0 on ARM, but 1 on x86 and PowerPC

Re: Tell HN: C Experts Panel – Ask us anything about C

#373

Earlier quoted context omitted.

You can very easily make a struct consisting of a pointer and length, is adding such a thing to the standard really a big deal? Personally, I don't see a problem with passing two arguments.

- In your example there's no guarantee that the length will be accurate, or that the data hasn't been modified independently elsewhere in the program. - In other words you've created a fantastic shoe-gun. One update line missed (either length or data, or data re-used outside the struct) and your "simple" struct is a huge headache, including potential security vulnerabilities. - Re-implementing a common error prone th…

In Delphi/FreePascal there are dynamic arrays (strings included) that are in fact fat pointers that hide inside more info than just length. All opaque types and work just fine with automatic lifecycle control and COW and whatnot.

Re: Tell HN: C Experts Panel – Ask us anything about C

#374

(1) Explain just how malloc() and free() work under the covers and the implications for multi-threading, memory leaks , virtual memory paging, etc. Maybe also cover some means, algorithms, and code for reporting on the state , status, etc. of the memory use by malloc() and free(). By the way, I know and have known well for longer than most C programmers have lived JUST what the heap data structure, as used in "heap s…

> But what is the meaning of "the heap" in C programming language documentation?

The C language standard does not contain the word "heap" anywhere; as far as C is considered, there is no "heap" in particular.

Re: Tell HN: C Experts Panel – Ask us anything about C

#375

(1) Explain just how malloc() and free() work under the covers and the implications for multi-threading, memory leaks , virtual memory paging, etc. Maybe also cover some means, algorithms, and code for reporting on the state , status, etc. of the memory use by malloc() and free(). By the way, I know and have known well for longer than most C programmers have lived JUST what the heap data structure, as used in "heap s…

It has been many years since a C++-to-C preprocessor has been commonplace. There's just too much new stuff in recent C++ to map it all easily into straight C.

Re: Tell HN: C Experts Panel – Ask us anything about C

#376

As there are a lot of C-masters lurking in this thread: How can one process unicode (UTF-8) properly in C? As a CJK person, I wish there was a robust solution. Are there any standardized ways or proposals? (Using wchar doesn't count.)

What sort of processing do you want to do?

Re: Tell HN: C Experts Panel – Ask us anything about C

#377
post #341

Open up WG14 mailing list for non-members? It's hard to appreciate what's going on at WG14 (or take part) when you can see the results only from afar, with none of the surrounding discussion. I recently read Jens Gustedt's blog on C2x where he casually recommended this as a way to get involved: "The best is to get involved in the standard’s process by adhering to your national standards body, come to the WG14 meeting…

Agreed. I would like to get involved, but I don't see any reasonable way for me to do that as an individual.

Re: Tell HN: C Experts Panel – Ask us anything about C

#378
post #118

Are there any plans to "clean up C"? A lot of effort has been put into alternative languages, which are great, but there is still a lot of momentum with C, and it seems that a lot of improvements that could be done in a backwards compatible way and without introducing much in the way of complexity. For example: - Locking down some categories of "undefined behaviour" to be "implementation defined" instead. - Proper ar…

There are "projects" underway to clean up the spec where it's viewed as either buggy, inconsistent, or underspecified. The atomics and threads sections are a coupled of example. There are efforts to define the behavior in cases where implementations have converged or died out (e.g., twos complement, shifting into the sign bit). There have been no proposals to add new array types and it doesn't seem likely at the core…

> C's charter is to standardize existing practice (as opposed to invent new features)

Passing a pair of arguments (pointer and a length) is surely one of the more universal conventions among C programmers?

Re: Tell HN: C Experts Panel – Ask us anything about C

#379

I know this opinion is unpopular and contradict with a core value of the C standardization committee but I personally think at some point, C standard should abandon supporting the legacy codebase. I think bool and stdint definitions should be available as part of the standard feature set and shouldn't need including their respective headers. These and some other features are available at the core of every modern lang…

We've started doing some things in this area, but I don't think the committee would abandon legacy code bases entirely. Instead, we try to make a migration path for code bases.

For instance, we added the '_Bool' data type and require you to include to spell it 'bool' instead and to get 'true' and 'false' identifiers. This was done to not impact existing code bases that had their own bool/true/false implementation with those spellings. Now that "enough" time has passed for legacy code bases to update, we're looking into making these "first-class" features of the language and not requiring to be included to use them. We're doing the same for things like _Static_assert vs static_assert, etc for the same reason.

Re: Tell HN: C Experts Panel – Ask us anything about C

#380

When will C gain a mechanism for "do not leave this sensitive information laying around after this function returns"? We have memset_s but that doesn't help when the compiler copies data into registers or onto the stack.

This is an entire language extension, as you note. The last time various people interested in this were in the same room (it was in January 2020 in a workgroup called HACS), what emerged was that the Rust people would try to add the “secret” keyword to the language first, since their language is still more agile than C, while the LLVM people would prepare LLVM for the arrival of at least one front-end that understand…

Thanks for the update. I was encouraging some of the people who were going to be at HACS to address this but I hadn't heard the latest progress. Unfortunately I couldn't be there myself.
Post reply on HN