New "MagPi Essentials" book : "Learn to code with C"
https://www.raspberrypi.org/magpi/issue ... ials-c-v1/
PeterO
He added that the MagPi people are keen to get more books and articles written on more technical subjects such as more advanced C topics.simon wrote: "To be honest, this book only got written because I suggested to the MagPi staff that I would write one on creating GTK+ applications, and it then occurred to me that an understanding of basic C would be a prerequisite, so the GTK application guide was postponed by a year or so.
So I do already have vague plans for writing a "programming for the desktop in C" book, which would be primarily about GTK GUI code, some stuff on glade, some basic GLib stuff, that sort of thing - I probably won't be starting work on it until next year at the earliest.
You've been doing it wrong for 35 years?mikronauts wrote:K&R notation is green, saves quite a bit of paper by not wasting empty lines on the '{' bracket... and you can see more lines in an editor.
I've been programming in C for >35 years, K&R RULEZ!!!!
I'm with James.jamesh wrote:You've been doing it wrong for 35 years?mikronauts wrote:K&R notation is green, saves quite a bit of paper by not wasting empty lines on the '{' bracket... and you can see more lines in an editor.
I've been programming in C for >35 years, K&R RULEZ!!!!
What! I had no idea you could do it in any other style than K&R and still call yourself a C programmer!jamesh wrote:You've been doing it wrong for 35 years?mikronauts wrote:K&R notation is green, saves quite a bit of paper by not wasting empty lines on the '{' bracket... and you can see more lines in an editor.
I've been programming in C for >35 years, K&R RULEZ!!!!
I'm ambi-editor-ouskarrika wrote:Don't say that you also use emacs instead of vi?
The idea that it is okay for a teacher to lie in order to make a subject easier for the students to learn seems misapplied here. It is disappointing that an otherwise nice introduction to C is spoiled by getting "hello world" wrong.jojopi wrote:Just "int main()" is valid in all C standards, and is the shortest and least "scary" option.
Well, it's swings & roundabouts. Back in K&R I'd have happily written "void main(..)" because it meant you didn't care about the return value. Obviously "int main(..) {/*code*/;return 0;}" is the most portable way to proceed and because "argc,argv" can be omitted that concept does not have to be introduced until later.AndyD wrote:Thanks @jojopi, I was beginning to think I was the voice in the wilderness.
Code: Select all
void main()
{printf("foo\n";}
K&R C does not include void. That came afterwards and is included in the ANSI standard.swampdog wrote:Back in K&R I'd have happily written "void main(..)"
Wikipedia wrote:In the years following the publication of K&R C, several features were added to the language, supported by compilers from AT&T (in particular PCC[15]) and some other vendors. These included:
. void functions (i.e., functions with no return value)
. functions returning struct or union types (rather than pointers)
. assignment for struct data types
. enumerated types
Both the int main() thing and the -Wall thing could be introduced in one of the more advanced chapters.a reasonable compromise to make for the sake of simplicity and not overloading the reader with unnecessary details.
tito-t wrote:Didactically great structure with very easily comprehensible code examples and detailed easy-to-understand explanations, even for non-English native speakers
Clear and informative layout with code blocks, screenshots and teaching texts -
Impressive and awesome, I love it!
Hopefully there will be some extensions and follow-ups:
C for GPIOs
C for UART, i2c and SPI
C for HATs
C for graphics
C for the Pi Cam
C for audio
Yes that is the list I was thinking about, but I've not had my first cup of tea yettito-t wrote:I agrre aboutBoth the int main() thing and the -Wall thing could be introduced in one of the more advanced chapters.a reasonable compromise to make for the sake of simplicity and not overloading the reader with unnecessary details.
About follow-up topics, I have already posted some proposals, what about them?
They would lead to more Linux- and especially more Pi- and Debian-related C subjects and issues (in random order):
tito-t wrote:Didactically great structure with very easily comprehensible code examples and detailed easy-to-understand explanations, even for non-English native speakers
Clear and informative layout with code blocks, screenshots and teaching texts -
Impressive and awesome, I love it!
Hopefully there will be some extensions and follow-ups:
C for GPIOs
C for UART, i2c and SPI
C for HATs
C for graphics
C for the Pi Cam
C for audio
Code: Select all
tgi_setcolor(COLOR_RED);
tgi_bar(xmin, ymin, xmax, ymax);
tgi_goto(x, y);
tgi_lineto(x, y);
tgi_outtext(str);Code: Select all
joy = joy_read(JOY_1);
if (JOY_BTN_RIGHT(joy)) {
steering += speed;
if (steering > 100) steering = 100;
}
if (JOY_BTN_LEFT(joy)) {
steering -= speed;
if (steering < -100) steering = -100;
}Actually it just does "b puts" so it returns whatever puts() returns, presumably gcc knows it will be zero for the standard.swampdog wrote:..would in fact end up returning the result of printf(), as would "int main()" in fact because there was no implicit "return 0" generated. I dunno arm asm but on the face of it the same thing appears to happen.Code: Select all
void main() {printf("foo\n";}
Wikipedia is not wholly correct unless it mentions many of the K&R compilers supported variants of the "up and coming" ansi standard for years prior to it becoming official.ejolson wrote:K&R C does not include void. That came afterwards and is included in the ANSI standard.swampdog wrote:Back in K&R I'd have happily written "void main(..)"Wikipedia wrote:In the years following the publication of K&R C, several features were added to the language, supported by compilers from AT&T (in particular PCC[15]) and some other vendors. These included:
. void functions (i.e., functions with no return value)
. functions returning struct or union types (rather than pointers)
. assignment for struct data types
. enumerated types