Live data from Hacker News

Learn C in Y Minutes

learnxinyminutes.com

1–10 of 81 posts

Re: Learn C in Y Minutes

#4

The author recommends -std=c99 (-pedantic) default flags, yet suggests K&R (2nd edition, presumably) as a reference...

Little reason to not use at least -std=c11 these days

Linux is C99, most microcontrollers use C99 or even C89. It would be nice to get the new features, but it's not always possible.

Re: Learn C in Y Minutes

#5
Oh man, multiple declaration on the single of code is nasty. Passing this kind of advice causes the beginners to develop bad habits.

At least these are not uninitialised variables.

  // Shorthands for multiple declarations:
  int i1 = 1, i2 = 2;
  float f1 = 1.0, f2 = 2.0;

  int b, c;
  b = c = 0;
Edited:.. After 1hr of posting my original comment, I noticed that there many opinions here.

I should have added why I think this is bad. Readability and maintenance. I would rather it have one line per declaration like the following..

   int i1=2;
   int i2=2;
Each variable easier to be changed, and reading it is clearer as there are no ambiguity to its type.

A common error I have see from "the multiple declarations in the single line" construct is that changing the type impacts all the variables whereas the intention was only for the first variable.

Re: Learn C in Y Minutes

#7

The author recommends -std=c99 (-pedantic) default flags, yet suggests K&R (2nd edition, presumably) as a reference...

Also, why still use the old confusing long, short, long long etc... types when the much better fixed-width types had been standardized in stdint.h since C99 (even the Visual Studio C compiler has those since at least VS2015).

Re: Learn C in Y Minutes

#8

Oh man, multiple declaration on the single of code is nasty. Passing this kind of advice causes the beginners to develop bad habits. At least these are not uninitialised variables. // Shorthands for multiple declarations: int i1 = 1, i2 = 2; float f1 = 1.0, f2 = 2.0; int b, c; b = c = 0; Edited:.. After 1hr of posting my original comment, I noticed that there many opinions here. I should have added why I think this i…

This is also bad advice for C:

   void function_1();
Most people coming from other languages (like C++) will probably think that this is identical with "void function_1(void)", but without the explicit void argument list, the compiler will not warn if the function is accidentally called with parameters.

Re: Learn C in Y Minutes

#9

Oh man, multiple declaration on the single of code is nasty. Passing this kind of advice causes the beginners to develop bad habits. At least these are not uninitialised variables. // Shorthands for multiple declarations: int i1 = 1, i2 = 2; float f1 = 1.0, f2 = 2.0; int b, c; b = c = 0; Edited:.. After 1hr of posting my original comment, I noticed that there many opinions here. I should have added why I think this i…

What is the “correct” version of this?

Re: Learn C in Y Minutes

#10

The author recommends -std=c99 (-pedantic) default flags, yet suggests K&R (2nd edition, presumably) as a reference...

Little reason to not use at least -std=c11 these days

MSVC has C11 support only since very, very recently:

https://devblogs.microsoft.com/cppblog/c11-and-c17-standard-...

(it has a solid subset of C99 since around VS2015 though, just _Generic was missing - and ignoring VLAs, which have been "dropped" in later C standards anyway).

Post reply on HN