Live data from Hacker News

Massacring C Pointers

wozniak.ca

291–300 of 300 posts

Re: Massacring C Pointers

#291

When I started my CS degree the school was transitioning from teaching C++ to teaching Java, and the state of instruction in C++ was almost as bad as these examples. I had a professor who wanted us to use "new Foo()" everywhere in our code (even local / static variables) because it, "gets the students ready for Java." No matching delete, of course, or mention of RAII. We were supposed to "pretend" we had a garbage co…

Some of my professors also have ridiculous code standards or exam standards. One of them teaches "algorithms and data structures", but he's not allowing us to even use a break or continue in our loops because he thinks it's "bad practice". We end up with a nested hellhole. Another example from the same professor (correct me if I'm wrong on this as I'm not a C++ expert), but he's constantly inheriting from unique or s…

> but he's not allowing us to even use a break or continue in our loops because he thinks it's "bad practice".

I will never in a million years understand why some people believe this.

Re: Massacring C Pointers

#292
post #22

Earlier quoted context omitted.

I'm sorry, but I don't think you've quite gotten the reasons why it was lambasted: > Not only does it not check, the design of the function means that there is no possible way for it to check safely. s and t are both pointers to characters? How long are the strings they might represent supposed to be? strlen > This leads into the second problem and one that is more subjective: this code is incredibly dense and relies…

strlen is not safe and the design of this function does not permit it to ever be safe. That is my point. Most "nice" C functions are also not used as teaching examples. There's a difference in how one writes C code for production use and instructive use.

You haven’t read K&R C I’m going to guess. Terseness is a traditional component of C and UNIX (cf creat). I don’t care to debate the merits but that is a fact. Most C books in the 80s were written in this style. Furthermore in the days or micros code was generally terse for many and varied reasons. There were people typing code on membrane keyboards.

Re: Massacring C Pointers

#293
post #86

Earlier quoted context omitted.

Better yet, just use the fact that NULL is false and get shorter, cleaner, and safer code. if (!s)

God no... explicit is better than implicit. Your statement there just does not read correctly, always have the condition explicit.

What is not explicit about that statement? The evaluation of the variable is well defined in a Boolean context.

If you have to write “== true” everytime that’s your own idiosyncratic hangup. It has nothing to do with explicitness, it’s just redundant. The true test was explicit the moment you wrote if (

Re: Massacring C Pointers

#295
post #94

The fixed-location variable allocation strategy the author mentions is called overlaying or compile-time stack[0]. It's still very much alive today, thanks to architectures like 8051 that are not really stack-friendly (even though they do have a stack). > The Keil C51 C Compiler works with the LX51 Linker to store function arguments and local variables in fixed memory locations using well-defined names [0] http://www…

Maybe this weird strategy exists elsewhere, but he's supposedly teaching Borland Turbo C with the small memory model.

That compiler uses a run-time call stack.

Re: Massacring C Pointers

#296
post #66

Apparently Mr Traister has written a number of other books - https://www.amazon.com/default/e/B001H6UPHY/ - according to Amazon... Made me wonder if the quality of the content in the other 11 books is anything like the one the Woz took apart.

It's not Steve Wozniak. They just happen to share the same last name. From https://wozniak.ca : > I’m Geoff Wozniak, just one of those persons on the Internet. My blog is hosted here, but not much else at the moment.

Thank you!

Re: Massacring C Pointers

#297

Earlier quoted context omitted.

Your last sentence is intriguing to me. I understand all the words, and I think I get the gist, but I'm not familiar with any of it. What is CSE? Google seems to think it's Certificate of Secondary Education. So, middle school -> early high school equivalent? Grade 1? A level? Leave where, the school? (I'm in the US, so that's probably the disconnect)

At that time there where two sets of exams taken at 16 O levels and CSE. The O levels where for Kids in grammar and private schools and the CSE's where for the kids who went to secondary modern schools who left at 15/16. As I was dyslexic I was put in the CSE stream though I did get a grade 1 in maths and computer studies which is the same as a pass at O level I didn't get to do A level computing.

Thanks!

Re: Massacring C Pointers

#299
post #281

Earlier quoted context omitted.

God no... explicit is better than implicit. Your statement there just does not read correctly, always have the condition explicit.

Why? It reads nicely as "if there is no string", can't get more explicit than that.

The biggest problem I have with this style is that it is inconsistent across variable types and provides no insight into the actual operation being performed without further knowledge. My personal experience is that my ability to read and comprehend code quickly is dependent on the context and patterns present within it (among other things). Therefore making the expression explicit as a pattern adds context and therefore increases readability and comprehension.

The statement '!x' tells me nothing about x, just that I'm expecting a given logical value. The semantic meaning of that value however, I have no idea. Odds are it is probably a NULL or 0, but that doesn't help much because (at least in the linux world) they can have different meanings despite having the same logical value. I cannot differentiate between success (!(x == NULL)) or failure (!(x == 0)) without more context.

The statement 'x == NULL' immediately tells me at a glance that I am dealing with a pointer, and therefore I should pay more attention to how it is used. I know I should now be looking for other patterns of safe/unsafe pointer management that are immediately relevant to the function I am reading right now. There is no need for me to look elsewhere and go on some tangent to find out, then to have to recall what I was doing when I come back later. I can immediately start considering the likelihood of segmentation faults, or other memory management issues. x == NULL also tells me that here I am expecting failure of some kind. The context around that condition should then tell me which kind, eg NULL == alloc_thing() vs NULL == find_thing().

Similarly, the statement 'x == -1' tells me I am working with an integer. This can tell me immediately whether I am expecting success (x == 0), failure (x == -1), or that I should make a mental note of more complex possibilities (THING_WORKED == do_thing()).

Code is a narrative. It is documenting the answers to the questions you are asking while writing it, and it should answer the questions that someone else is asking while reading it. When somebody asks you to explain something, the least helpful thing you can do is answer a plain "yes" or "no". It is better to give context and answer further related questions before they need to be asked. Readability and comprehension of code are no different - any given programmer is asking questions of the code. The more questions they have to ask, the longer it will take them to discover the answers in order to understand the code. Context helps. Shorter is not always better.

Re: Massacring C Pointers

#300
GARRY COLE We are a group of professional hackers,we are seasoned and professional hackers ...as a way of giving back to the world we are here to help with all hacking jobs some of which are , HACK INTO ANY SCHOOL DATABASE AND CHANGE UNIVERSITY GRADES, no matter how secured...Find out if your partiner is cheating ...... - Hack INTO ANY BANK WEBSITE - Hack into any COMPANY WEBSITE - HACK INTO ANY GOVERNMENT AGENCY WEBSITE - HACK INTO SECURITY AGENCY WEBSITE AND ERASE CRIMINAL RECORDS - Hack into CRAIGSLIST AND REMOVE FLAGGING - HACK INTO ANY DATABASE SYSTEM - HACK PAYPAL ACCOUNT - HACK WORD-PRESS Blogs - SERVER CRASHED hack - UNTRACEABLE INTERNET PROTOCOL etc - HAVE YOU OR YOUR CHILD BEEN BULLIED ONLINE BEFORE AND WANT TO GET BACk this are few among alll we can do try us out and you will not be disappointed we do all jobs with HONESTY .... Contact easyhackingguru@gmail.com WhatsApp/text:--- +12168104481
Post reply on HN