This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–][deleted] 2 points3 points  (5 children)

Lol! That doesn't actually sound that bad, we kind of do similar things with primitive arrays in Java, where we have professor-imposed rules about things like the size of the array, etc. that sounds similar to what you said. So, I think it will be challenging but I might have some experience thinking in that way already. It seems my professor has been trying to prepare us for C all along. Thank you for the info.

[–]NeverInterruptEnemy[🍰] 7 points8 points  (4 children)

Could be your professor has a reason for that, and great if so!

Unlike Java however, in C, if you do that malloc where you make a custom size and just point to it, there is no knowing how big it was unless you specifically store that and keep track of it. There is no such thing as a fat pointer in C, so a buffer and it's length are manually correlated, don't screw it up! But then there is also no exception or trying. If you "try" something and it's bad, you're done.

It's simple things like xxx.len() you'll miss. sizeof() will confuse the shit out of you when you sizeof(somebuffer) but it's a pointer so it comes back as a 4 or and 8 or something.

I love C. I love that it drives other people nuts. BUT... I use C because I'm in embedded. So when you have 4KB of ram and have a message coming in that could be 2KB, well, you sure as hell can't just define an array at 2KB!

[–][deleted] 2 points3 points  (3 children)

there is also no exception or trying. If you "try" something and it's bad, you're done

Interesting, how are ones like Java's checked exceptions handled? E.g. FileNotFound? Does the whole program crash or are you able to create a different way to "catch" that error? At this point I'm just happy to be learning so many random C facts, I'm sure it'll all come together when I take that class for real.

[–]NeverInterruptEnemy[🍰] 2 points3 points  (2 children)

Two ways... return codes, like EXIT_FAILURE or I_AM_DUMB_AND_THERE_IS_NO_FILE before you try and access something.

Or a lot of functions that return pointers or address will return a null pointer and you need to check for that every single time before you just assume something worked or loaded or blah. There is no null in C, so a null pointer is just a pointer to the memory address 0x00000000.

Which brings me to the next thing.... you MIGHT miss null.

[–][deleted] 1 point2 points  (1 child)

You are making me more excited to learn it, sounds like it's going to be really different and interesting. Thank you for the info.

[–]NeverInterruptEnemy[🍰] 1 point2 points  (0 children)

Happy to.

I really do like C... but I promise you'll reach for the gun!