Skip to main content

Timeline for LinkedList data structure in C

Current License: CC BY-SA 4.0

13 events
when toggle format what by license comment
Jun 23 at 14:54 comment added Ray @Fe2O3 Yeah, but there's no ordering that'll make the compiler catch that one, so oh well. (It's not like I ever actually make any of these typos; as you say, if I were that careless, I'd have bigger problems. I just like coding defensively (if it doesn't add inefficiency or verbosity) on general principle.)
Jun 20 at 19:47 comment added user272752 @Ray PS: if one mistypes "==" as an invisible bug, "=", then one's as likely to type "<=" as "=", too... Or, just "<" when one intended "<="... Jus' sayin'
Jun 20 at 19:44 comment added user272752 @Ray You're free to use whatever works for you. I would 'bridle' at the prospect of what I now consider a "micro-guideline" applicable to only 1 of 6 "fraternal twin" operators, and only useful when one side is a compile-time constant... I'd storm out of any code review meeting, and out the front door. But that's just me... (These days I only write app code for my own pleasure, so a bug is no big issue; sometimes one provides even more entertainment!) It's your code, your choice. Were I to try to do this, I'd be writing an increasing number of bugs into my code... Cheers! :-)
Jun 20 at 16:27 comment added Ray @chux Yeah, I thought about mentioning that, but the OP's a beginner and the sizeof(Foo*) >= sizeof(int) is going to be true on any hardware they'll be working on any time soon, so I decided to keep it simple. By the time they start playing with embedded systems or whatever, they'll understand alignment and won't need my advice.
Jun 20 at 16:17 comment added Ray @Fe2O3 "when comparing the equality of a constant and a variable" [emphasis added]. I'd write your example exactly the same way you did. More generally, I'd normally be on your side w.r.t. "pay attention". I don't like languages that automatically check my array bounds, for instance, since I write code that ensures I won't go off the end before it starts scanning in the first place, and I don't want my code being slower for no reason (although for code running as root, I'd probably accept that tradeoff) But in this case, it's zero cost and potentially catches a bug if I screw up, so why not?
Jun 20 at 13:01 comment added user272752 if ( 0 <= n && n < MAX ) ... Apply your "constant on left" rule to that and see if it is easy to scan and quickly interpret... The real solution is to PAY ATTENTION and NOT accidentally use assignment when you mean equality. That sort of mistake is a strong indication there are likely to be 'deeper' bugs hidden elsewhere in the code or flow...
Jun 18 at 21:06 comment added chux "Good call putting the fields in descending order of size; this keeps padding to a minimum." -->A reasonable goal, yet pointers may be narrower than int. Yet even in that case, the order suggested is good.
Jun 18 at 0:58 history edited mdfst13 CC BY-SA 4.0
By the time that you're in an answer, you've already gone through two layers of header and are on 3rd level headers (questions are only on the second level of headers).
Jun 17 at 17:45 history edited Ray CC BY-SA 4.0
deleted 30 characters in body
S Jun 17 at 17:39 review First answers
Jun 18 at 1:05
S Jun 17 at 17:39 history edited Ray CC BY-SA 4.0
deleted 30 characters in body
S Jun 17 at 16:52 review First answers
Jun 17 at 17:29
S Jun 17 at 16:52 history answered Ray CC BY-SA 4.0