Live data from Hacker News

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

news.ycombinator.com

291–300 of 978 posts

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

#291
post #262

Earlier quoted context omitted.

I tried, but two spaces yielded what you saw.

Huh, it also needed an extra line break before the first line of code. I didn't realize that! I've fixed it now.

You should be commended for the fast customer service!

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

#292
When deciding on standardized behavior for C operations or data representation that may favor some hardware over others [1], who argues the side of the various hardware vendors, if they have no members on the standardization committee?

Is it fair to assume that hardware-related decisions occur in an environment where members who are sponsored by vendors argue their employers case, rather an a neutral one?

---

[1] E.g., because some hardware's behavior may more naturally implement the operation.

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

#293
post #28

What is the story behind the removal of VLAs from C99 in later revisions?

They did not remove them, but made them optional.

Is a controverial feature, that can produce bugs, and are banned in a lot of project (one famouse, the Linux kernel).

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

#294
post #283

Does the following code fragment cause undefined behaviour? unsigned int x; x -= x; There's a lengthy StackOverflow thread where various C language-lawyers disagree on what the spec has to say about trap values, and under what circumstances reading an uninitialised variable causes UB. I'd appreciate an authoritative answer. Thanks for dropping by on HN! https://stackoverflow.com/q/11962457/

Yes, it's undefined. It involves a read of an uninitialized local variable. Except for the special case of unsigned char, any uninitialized read is undefined.

>Except for the special case of unsigned char, any uninitialized read is undefined.

Could you expand on this?

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

#295
post #226

Earlier quoted context omitted.

I've been doing the same! It certainly helps for strings. Pointer block diagrams (like K&R use) seem to help too. Mostly what melts their brains is the idea that an identifier can be "in two places at once" - for example, you can have a variable x declared in some scope and a function one of whose arguments is named x, and those are two different things.

Try explaining the concept of "scope", starting with nested blocks. It does require some practice. I suggest not unnecessarily reusing identifiers associated with different objects.

Thanks!

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

#297
post #283

Earlier quoted context omitted.

Yes, it's undefined. It involves a read of an uninitialized local variable. Except for the special case of unsigned char, any uninitialized read is undefined.

>Except for the special case of unsigned char, any uninitialized read is undefined. Could you expand on this?

Uninitialized Reads https://queue.acm.org/detail.cfm?id=3041020

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

#298

Earlier quoted context omitted.

In the same vein, I really like being able to use underscores in binary and hex literals to denote subfields in hardware registers. 0xDEADB_EEF 0b1_010_110111001001 etc.

Should take Verilog binary construction syntax, like { 12'd12, 16'hffee, 3'b101 } (or something similar that would fit with C's syntax).

Maybe not.

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

#299

Earlier quoted context omitted.

I am sorry I do not have an answer to your question. It's a very valid one and I would be interested in any pointer to an answer. What I can say while we are on the subject, is that I have seen C code (most often C code that started its life in the 1990s, to be fair) that instead of showing an abstract struct in the public interface, showed a different struct definition. Please don't do this. Yes, when compiling nowa…

Wait, doesn't this mean that the BSD sockets API is inherently dependent on UB, casing different socket types to each other and sometimes only using the first few members, or am I misunderstanding you?

Yeah, it depends on well agreed convention but which is ub according to the standard.

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

#300

Now that C2x plans to make two's complement the only sign representation, is there any reason why signed overflow has to continue being undefined behavior? On a slightly more personal note: What are some undefined behaviors that you would like to turn into defined behavior, but can't change for whatever reasons that be?

Signed overflow being undefined behavior allows optimizations that wouldn't otherwise be possible Quoting http://blog.llvm.org/2011/05/what-every-c-programmer-should-... > This behavior enables certain classes of optimizations that are important for some code. For example, knowing that INT_MAX+1 is undefined allows optimizing "X+1 > X" to "true". Knowing the multiplication "cannot" overflow (because doing so would be…

> for (i = 0; i The worst thing is that people take it as acceptable that this loop is going to operate differently upon overflow (e.g. assume N is TYPE_MAX) depending on whether i or N are signed vs. unsigned.
Post reply on HN