Live data from Hacker News

So you think you know C? (2016)

wordsandbuttons.online

261–270 of 344 posts

Re: So you think you know C? (2016)

#262

Having written a conforming C compiler, at one point I knew everything there was to know about C (I forget details now and then, or confusing them with C++ and D). But knowing every engineering detail is not the same thing as knowing how to program in C effectively. It's like being the engineer who designs a Grand Prix car. It does not mean you can drive it faster around the track than anyone else. Not even close. Fo…

How ('yeah im going to write this') do you start such project like a c compiler? Seems like a huge thing to write. What did you write first? Did you already have a lot of compiler knowledge so you had a good idea/structure/flow etc in your mind already? And how long did it take you?

tia

Re: So you think you know C? (2016)

#263
post #260

Earlier quoted context omitted.

I don't know if POSIX specifies CHAR_MAX, but on most systems, storing the value into a char will change the value, making it everything but 416: https://tio.run/##S0oszvifnFiiYFeSWlyil6xgY@Pq7/Y/M69EITcxM0...

[deleted]

[deleted]

Re: So you think you know C? (2016)

#264

Having written a conforming C compiler, at one point I knew everything there was to know about C (I forget details now and then, or confusing them with C++ and D). But knowing every engineering detail is not the same thing as knowing how to program in C effectively. It's like being the engineer who designs a Grand Prix car. It does not mean you can drive it faster around the track than anyone else. Not even close. Fo…

How ('yeah im going to write this') do you start such project like a c compiler? Seems like a huge thing to write. What did you write first? Did you already have a lot of compiler knowledge so you had a good idea/structure/flow etc in your mind already? And how long did it take you? tia

A compliant C compiler is probably a year's work in a modern language give or take?

Re: So you think you know C? (2016)

#265
post #245

Earlier quoted context omitted.

map/filter/reduce is simpler, but it takes some getting used to. Loops have worn a deep rut in my brain.

As someone who was introduced to programming via map/filter/reduce, for loops are incredibly more complicated. I don’t think I’ve ever written one correctly on first try.

Are you primarily a JS/front-end dev?

Because this is crazy to me! Some languages only use for loops (Go).

Re: So you think you know C? (2016)

#266
post #250

Earlier quoted context omitted.

There were multiple questions where I would have answered "It's undefined" or "It's implementation defined", but those weren't options. It's not that I don't know the answer; I know the answer ("it's implementation defined according to the spec, but on essentially every relevant platform, the result will be X"), but the "it's implementation defined" part of my answer isn't an option, so the only possible answer becom…

the quiz asks what each one would evaluate to. “Undefined” or “implementation dependent” are not answers to that question. “I don’t know [because it is undefined]” or “I don’t know [based on the given information]” are logically consistent answers to the question that was asked

Ok, say I made a quiz where I ask you about what `((((16 > 16) My point isn't that there's no logically consistent answer. My point is that there are _two_ logically consistent answers, and which one is correct depends on the unknowable state of mind of the quiz author. On the other hand, if the options included "It's implementation defined" or "it's undefined", the author would have made their expectations clear, and the quiz would actually test people's knowledge of C rather than people's ability to try to reason about what sort of answer the author expects.

Re: So you think you know C? (2016)

#267
post #245

Earlier quoted context omitted.

As someone who was introduced to programming via map/filter/reduce, for loops are incredibly more complicated. I don’t think I’ve ever written one correctly on first try.

Are you primarily a JS/front-end dev? Because this is crazy to me! Some languages only use for loops (Go).

Full-stack, spent most of my time on the backend in ruby or scala.

Re: So you think you know C? (2016)

#268
post #221

Earlier quoted context omitted.

Over time I removed all the C preprocessor tricks from my own code and just wrote ordinary C in its place. Much better. I don't get it. If my macros produce standards-compliant code and they make my code easier to read and understand, why shouldn't I use them? My goal as a developer is to write clean performant bug-free code... not to make life easy for compiler developers.

Because when you work on a team, not everyone is a C Gandalf, probably not even yourself a couple of months later when fixing a bug with everyone screaming that the system is down. Exaggerating here, but rule of thumb is that it takes twice to debug as it takes to write it, so how long do you want to take to do maintenance fixes?

Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it.

--Brian Kernighan

Re: So you think you know C? (2016)

#269
post #252

But a code based on several standards, not only on C standard. For example we know, that basic source character sets should contain space (C11 5.2.1), we know that character constants has type "int" and that character constants represent value equal to the code of a symbol (C11 5.4.4). We know used source character set and we know code of the space character. We can configure specific source character set on the POSI…

I don't know if POSIX specifies CHAR_MAX, but on most systems, storing the value into a char will change the value, making it everything but 416: https://tio.run/##S0oszvifnFiiYFeSWlyil6xgY@Pq7/Y/M69EITcxM0...

My mistake: We have (32*13) with minimal possible CHAR_BIT is 8. So it either 416 for char bigger then eight bits, or 160 for unsigned eight bits char, or -96 for signed eight bits char. Then it extended to the signed integer value (one of this three values), and then we got result as (int)(status & 0377). For all three cases result will be 160.

Re: So you think you know C? (2016)

#270
Went to an IRC chat room when I was learning C in school. Asked if you could return a pointer to something that lives on the stack. Was talked down by an all-knowing dude telling me to go read K&R again. Proceeded to write a code sample [1] that showed it is possible (it's not really stable but works reliably in recursive calls IIRC).

I do not like this attitude (then again it was just one random dude).

[1] https://www.onlinegdb.com/HyO5VXRxS

Post reply on HN