Earlier quoted context omitted.
I'd say both statements are correct. Compiler implementers are happy when they don't have to care about some edge case because then the code is simpler. Thus, only for unsigned counters there is the extra logic to compile them correctly. That is my interpretation of "The opposite is the case". Writing a compiler is easier with lots of undefined behavior.
But that's backwards, the compiler writers are writing special cases to erase checks in the signed case. Doing the 'dumb' thing and mindlessly going through the written check is simpler which is why that's what compilers did for decades as de facto standard on x86.
Tell HN: C Experts Panel – Ask us anything about C
861–870 of 978 posts
Re: Tell HN: C Experts Panel – Ask us anything about C
#862Earlier quoted context omitted.
>clean up the spec Would this involve further specification of bitfields? Feel implementation defined nature of bitfields limits potential
What parts of bitfields are implementation defined?
Re: Tell HN: C Experts Panel – Ask us anything about C
#863Earlier quoted context omitted.
It's a three year rotation: Python, C (Unix), C (Arduino). My goal with the class is to teach ideas that will stand the test of time. C (and Unix) certainly fit that bill. Happily, the tooling is the easiest part. Every student has a rasberry-pi running debian, no mouse, no window server, and no extraneous software. You can spool kids up on a nano-based C toolchain in one class period with remarkably few sharp edges.…
Neat! I think your choice of C and Python as the languages to be taught is very right. The idea of showing the use of C in both Desktop/Server and Embedded environments has long been the approach i had advocated. C is truly the de-facto "universal" language and students should be made aware of it from the start. I would suggest the following additions; * The Arduino "language" is C++. Use this as a gentle introductio…
For the arduino, I’m really interested in teaching control systems. So we will start with finite state machines and go from there to implementing PID controllers. I’m intrigued by the idea of avoiding the IDE, so will totally pick up that book!
Re: Tell HN: C Experts Panel – Ask us anything about C
#864Earlier quoted context omitted.
Sure you can. int aFoo[]; has many legal array operations possible: *(aFoo+3) should work fine and return the 4th int in the array.
I think your star operator there is making the compiler cast your array to pointer implicitly.
Re: Tell HN: C Experts Panel – Ask us anything about C
#865Earlier quoted context omitted.
Is this a real concern, beyond 'experts panel' esoteric discussion? Do folks really put a number into an int, that is sometimes going to need to be exactly TYPE_MAX but no larger? I've gone a lifetime programming, and this kind of stuff never, ever matters one iota.
The very few times I've ever put in a check like that, I always do something like i < MAX_INT - 5 just to be sure, because I'm never confident that I intuitively understand off-by-one errors.
Re: Tell HN: C Experts Panel – Ask us anything about C
#866For example, I have a arbitrary number of includes, each of them declare a struct that need to be listed later on.
#define MOD_LIST // start with an empty list
#include "mod/a.c"
// MOD_LIST is: a,
#include "mod/b.c"
// MOD_LIST is: a,b,
Module modules[] = {
MOD_LIST
}Re: Tell HN: C Experts Panel – Ask us anything about C
#867Earlier quoted context omitted.
That's a really bizarre layout for your struct. Why don't you put the length first?
Why would it matter? The bytes aren't inline, this is just a struct with two word-sized fields. A possible tiny advantage for this layout is that a pointer to this struct can be used as a pointer to a pointer-to-bytes, without having to adjust it. Although i'm not sure that's not undefined behaviour.
https://github.com/python/cpython/blob/master/Include/object...
Re: Tell HN: C Experts Panel – Ask us anything about C
#868Earlier quoted context omitted.
You do have to understand that compiler teams aren't saying something like "this triggers UB, quick just replace it with noop." It's just something that naturally happens when you need to reason about code. For example, consider a very simple statement. let array[10]; let i = some_function(); print(array[i]); The function might not even be known to the compiler at compilation time if it was from a DLL or something. B…
> But the compiler is like "hey! you used the result of this function as an index for this array! i must be in the range [0, 10)! I can use that information!" As a developer who has seen lots of developers (including himself) make really dumb mistakes, this seems like a very strange statement. Imagine if you hired a security guard to stand outside your house. One day, he sees you leave the house and forget to lock th…
Re: Tell HN: C Experts Panel – Ask us anything about C
#869Re: Tell HN: C Experts Panel – Ask us anything about C
#870Are 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…
I agree which brought me into looking at Zig. A future version of C might disallow macros, preprocessor, disallow circular libraries, include a module system, but allow importing legacy libs like Zig. Also something like llvm so we can automatically do static analysis, transforms would be great.
I am not an expert at either C or Zig, so I would appreciate any feedback from anyone who can more intelligently compare the two.