Popular posts from this blog
Poor Documentation - How Could You Do this to Us K&R?
Exercise 4-3. Given the basic framework, it's straightforward to extend the calculator. Add the modulus (%) and unary minus operators. Add an "erase" command which erases the top entry on the stack. Add commands for handling variables. (Twenty-six single-letter variable names is easy.) Really? How about some examples that tell us what to expect for us to parse? Chatting with GPT, I get variable assignment : <value> <variable> := And for unary minus: <value> u- So, essentially, we have new operators. How are we supposed to know what to expect? What will getop send us - given that we're to expect a single character? That's one thing. Now, given that 'c' is a command that tells you to do something, how are you supposed to deal with a variable named c, which they claim is easy? Actually, looks like it's a hack by Dr. Chuck. The actual textbook has the getop discussed before the exercise, which makes things easier to understand..
A Classic C Programming Mistake - See if You Can Spot it
size_t *sz_out; *sz_out = input[sz_in-1] - input[0]+1; int * output = (int *) malloc( *sz_out ); Nail it? That's right, you have to be specific in the malloc call. If you give it just a number (in this case, sz_out is a number of bytes - size of output) it'll allocate that many bytes - not what you want. You always use malloc along with the sizeof operator to get the allocation right. Live and learn.
Comments
Post a Comment