RE: [SLUG] Wanting to learn C - book suggestions?

From: Ken Elliott (kelliott4@tampabay.rr.com)
Date: Fri Mar 11 2005 - 07:33:26 EST


>>Nitpick: Technically that's not correct ANSI C.

Who said I was writing ANSI? I'm an old C guy, so I write in K&R C...<grin>

You nailed me on the semi-colon. And I should have included stdio.h, but it
was a bit of a joke, not an entire program meant to be compiled.

Good catch, however. Not a bad idea to point out my out-of-date style to
prevent others from following the same path.

Ken Elliott

=====================
-----Original Message-----
From: slug@nks.net [mailto:slug@nks.net] On Behalf Of Dylan Hardison
Sent: Friday, March 11, 2005 1:58 AM
To: slug@nks.net
Subject: Re: [SLUG] Wanting to learn C - book suggestions?

On Thu, 10 Mar 2005 21:19:19 -0500, Ken Elliott
<kelliott4@tampabay.rr.com> wrote:
> >>printf("\n");
>
> >>has more characters than
>
> >>echo ""
>
> >>plus compilation. Not to say it's a _bad_ method, though.
>
> Yes, but the C version prints nothing _so_ much faster...
>
> main() {prinf("doh!\n")}

Nitpick: Technically that's not correct ANSI C.

* The return type (int) should be specified.
* printf is not declared.
* printf really shouldn't be used for this, puts should be. Some (stupid)
   implementations of varargs don't handle vararg functions with only
on argument.
* the semicolon after printf is missing.
* There is no return statement. main must return an integer value.

Though, at least you didn't write "void main".
That's so completely incorrect, and I can't say how many times I've
seen people type that on slashdot...

A correct implementation would be:
#include <stdio.h>
int main() {
    puts("doh!");
    return 0;
}

Sorry for being pedantic and nit-picky, I had to deal with some very
ugly non-standard C code today. :)
-----------------------------------------------------------------------
This list is provided as an unmoderated internet service by Networked
Knowledge Systems (NKS). Views and opinions expressed in messages
posted are those of the author and do not necessarily reflect the
official policy or position of NKS or any of its employees.

-----------------------------------------------------------------------
This list is provided as an unmoderated internet service by Networked
Knowledge Systems (NKS). Views and opinions expressed in messages
posted are those of the author and do not necessarily reflect the
official policy or position of NKS or any of its employees.



This archive was generated by hypermail 2.1.3 : Fri Aug 01 2014 - 20:30:49 EDT