newbie to C pls help 
Author Message
 newbie to C pls help

hi,
I would be grateful if someone tell me where can i find the ANSI
standard to do C programming like, is it defined in the ANSI
specification

int main(){
return 0;

Quote:
}

instead of

void main(){

Quote:
}

char *c = malloc(sizeof(char)*100)
instead of
char* c = (char*) malloc(100);

warm regards
aneesh



Mon, 04 Apr 2005 16:56:47 GMT  
 newbie to C pls help

Quote:
> hi,
> I would be grateful if someone tell me where can i find the ANSI
> standard to do C programming like, is it defined in the ANSI
> specification
> int main(){
> return 0;
> }

Yes, this is the standard way of writing main().

Quote:
> instead of
> void main(){
> }

This is a non-standard form of main() which will invoke undefined
behaviour if used.

Quote:
> char *c = malloc(sizeof(char)*100)
> instead of
> char* c = (char*) malloc(100);

The factor sizeof(char) is redundant, as the standard defines
sizeof(char) to be 1. Strictly speaking, the cast to (char*) is
harmless, but in practical situations it should be avoided, as it
can mask out failure to #include <stdlib.h>, which is a serious
bug, and is not corrected by casting.

--

| Kingpriest of "The Flying Lemon Tree" G++ FR FW+ M- #108 D+ ADA N+++|
| http://www.helsinki.fi/~palaste       W++ B OP+                     |
\----------------------------------------- Finland rules! ------------/
"The day Microsoft makes something that doesn't suck is probably the day they
start making vacuum cleaners."
   - Ernst Jan Plugge



Mon, 04 Apr 2005 16:59:02 GMT  
 newbie to C pls help

Quote:
> hi,
> I would be grateful if someone tell me where can i find the ANSI
> standard to do C programming like, is it defined in the ANSI
> specification

www.ansi.org sells pdf-copies of ISO/IEC 9899:1999 via their
web-page.

Quote:

> int main(){
> return 0;
> }
> instead of

> void main(){

> }
> char *c = malloc(sizeof(char)*100)
> instead of
> char* c = (char*) malloc(100);

Both of the above malloc examples are ANSI or ISO compliant (if
the appropriate declaration of malloc is provided, i.e. by
including stdlib.h). Anyhow both have at least one problem even
if these don't count as violations of the standard.

sizeof(char) is by definition 1, so there is no point in wrinting
sizeof(char)*100, this for sue will evaluate to 100.

Casting mallocs return value is unnecessary. malloc returns a
void-pointer which can be converted to any other pointer type
implicitly without a cast.

So actually you should
char *c = malloc(100);

HTH, HAND
--

"LISP  is worth learning for  the profound enlightenment  experience
you will have when you finally get it; that experience will make you
a better programmer for the rest of your days."   -- Eric S. Raymond



Mon, 04 Apr 2005 19:36:49 GMT  
 newbie to C pls help

Quote:
aneeshmraj writes:
>I would be grateful if someone tell me where can i find the ANSI
>standard to do C programming like, is it defined in the ANSI
>specification

As near as I can tell the ANSI standard C is no longer available from ANSI.
The link in the FAQ leads to ISO/IEC 9899:1999 after a bit of frustrating
fiddling around.  The ANSI site seems to be powered by an overloaded 80286
computer.  The standard lised above is available in Adobe Acrobat fromat for 26
USD but compilers for that standard are as scarce as hen's teeth.

Perhaps the ISO aspect might lead to a standard that was actually implemented.

Or perhaps there is sufficient background and history in the :1999 document
that you can get by with it.  



Mon, 04 Apr 2005 20:39:59 GMT  
 newbie to C pls help

Quote:
>aneeshmraj writes:

>>I would be grateful if someone tell me where can i find the ANSI
>>standard to do C programming like, is it defined in the ANSI
>>specification

>As near as I can tell the ANSI standard C is no longer available from ANSI.

It certainly is.

Quote:
>The link in the FAQ leads to ISO/IEC 9899:1999 after a bit of frustrating
>fiddling around.

Well, this is also the current ANSI C standard: it's been approved by
ANSI on 2000-05-22.

Quote:
>The ANSI site seems to be powered by an overloaded 80286
>computer.  The standard lised above is available in Adobe Acrobat fromat for 26
>USD but compilers for that standard are as scarce as hen's teeth.

It used to be USD 18.  When did they increase the price?

Quote:
>Perhaps the ISO aspect might lead to a standard that was actually implemented.

???

Quote:
>Or perhaps there is sufficient background and history in the :1999 document
>that you can get by with it.  

Nope, there isn't.  It's impossible to figure out how the C89 standard
looked by using the C99 as the only source of information.

The closest to the original ANSI C89 standard you can still find on the
web is an imperfect ASCII version of its last public draft (I've put
a lot of work into improving it, the original being next to useless in
many places and horribly formatted, but there are still parts that need
to be fixed, like the escape sequences and the floating point model).

http://home.earthlink.net/~bobbitts/c89.txt

Dan
--
Dan Pop
DESY Zeuthen, RZ group



Mon, 04 Apr 2005 21:12:27 GMT  
 newbie to C pls help

Quote:
Dan Pop writes:
>>As near as I can tell the ANSI standard C is no longer available from ANSI.

>It certainly is.

>>The link in the FAQ leads to ISO/IEC 9899:1999 after a bit of frustrating
>>fiddling around.

>Well, this is also the current ANSI C standard: it's been approved by
>ANSI on 2000-05-22.

>>The ANSI site seems to be powered by an overloaded 80286
>>computer.  The standard lised above is available in Adobe Acrobat fromat for
>26
>>USD but compilers for that standard are as scarce as hen's teeth.

>It used to be USD 18.  When did they increase the price?

>>Perhaps the ISO aspect might lead to a standard that was actually
>implemented.

>???

>>Or perhaps there is sufficient background and history in the :1999 document
>>that you can get by with it.  

>Nope, there isn't.  It's impossible to figure out how the C89 standard
>looked by using the C99 as the only source of information.

>The closest to the original ANSI C89 standard you can still find on the
>web is an imperfect ASCII version of its last public draft (I've put
>a lot of work into improving it, the original being next to useless in
>many places and horribly formatted, but there are still parts that need
>to be fixed, like the escape sequences and the floating point model).

I figured my post would make you pop out of the woodwork.  It looks like I just
saved a lot of people, including myself, 18 USD.  

Not that I plan on reading it, you understand.  But it IS nice to have it.  

Thanks a lot!



Mon, 04 Apr 2005 21:54:43 GMT  
 newbie to C pls help
in comp.lang.c i read:

Quote:
>As near as I can tell the ANSI standard C is no longer available from ANSI.

incits/iso/iec 9899-1999 (formerly ansi/iso/iec 9899-1999), usd 18
<http://webstore.ansi.org/ansidocstore/product.asp?sku=INCITS%2FISO%2F...>

iso/iec 9899/cor1:2001, free
<http://ftp2.ansi.org/download/free_download.asp?document=ISO%2FIEC+98...>

Quote:
>Or perhaps there is sufficient background and history in the :1999 document
>that you can get by with it.  

that's the current standard, why would one merely `get by' with it?

--
bringing you boring signatures for 17 years



Tue, 05 Apr 2005 02:19:15 GMT  
 newbie to C pls help
in comp.lang.c i read:

Quote:
>Dan Pop writes:
>>The closest to the original ANSI C89 standard you can still find on the
>>web is an imperfect ASCII version of its last public draft
>I figured my post would make you pop out of the woodwork.  It looks like I
>just saved a lot of people, including myself, 18 USD.

foolishly.  the actual standard is far superior to any of the drafts.

--
bringing you boring signatures for 17 years



Tue, 05 Apr 2005 02:22:36 GMT  
 newbie to C pls help
in comp.lang.c i read:

Quote:

>(R124c4u2) writes:
>>The link in the FAQ leads to ISO/IEC 9899:1999 after a bit of frustrating
>>fiddling around.

>Well, this is also the current ANSI C standard: it's been approved by
>ANSI on 2000-05-22.

>>The ANSI site seems to be powered by an overloaded 80286 computer.  The
>>standard lised above is available in Adobe Acrobat fromat for 26 USD but
>>compilers for that standard are as scarce as hen's teeth.

>It used to be USD 18.  When did they increase the price?

the iso standard is usd 26, the incits version is usd 18, and it's the iso
standard to which the previous poster was referring.

--
bringing you boring signatures for 17 years



Tue, 05 Apr 2005 02:21:35 GMT  
 newbie to C pls help

Quote:
>>As near as I can tell the ANSI standard C is no longer available from ANSI.

>incits/iso/iec 9899-1999 (formerly ansi/iso/iec 9899-1999), usd 18

><http://webstore.ansi.org/ansidocstore/product.asp?sku=INCITS%2FISO%2FIEC
+9899%2D1999>

>iso/iec 9899/cor1:2001, free

><http://ftp2.ansi.org/download/free_download.asp?document=ISO%2FIEC+9899%
2FCor1%3A2001>

>>Or perhaps there is sufficient background and history in the :1999 document
>>that you can get by with it.  

>that's the current standard, why would one merely `get by' with it?

Because the current standard does not apply to most of the compilers in actual
use.  Some subset of it is what most people mean by ANSI C.  As far as I can
tell the standard for *that* language is no longer available from ANSI.  If you
can figure out what the subset is you can get by with it.  But, according to
Dan Pop, they are not going to tell you what that subset is in the 26 USD
document.  

And I don't want to get involved in some long, arcane, argument about the
meaning of "subset".  



Tue, 05 Apr 2005 02:59:48 GMT  
 newbie to C pls help
in comp.lang.c i read:

Quote:
>As far as I can tell the standard for *that* language

ansi c x3.159-1989 or iso/iec 9899:1990

Quote:
>is no longer available from ANSI.

ah, yes you are correct.  x3.159 is not available from ansi because it was
superseded by the adoption of the iso/iec standard, which has since been
superseded by a new revision.

if you'd like a useful working copy of c89/c90 then purchase a book that
contains or explains it, e.g., k&r v2 (or even schlidt as long as you
ignore his text), or locate a copy other than from your national body's
printer / outlet, e.g., a technical or used bookstore may still have a copy
laying around.

global engineering still lists them in their catalog, but x3.159 is listed
as canceled/superseded and 9899:1990 is listed as withdrawn/superseded so
it's unlikely you could order either of them, but you can scare yourself by
looking at the price (usd 148 and usd 237, respectively).

--
bringing you boring signatures for 17 years



Tue, 05 Apr 2005 04:29:36 GMT  
 
 [ 11 post ] 

 Relevant Pages 

1. Newbie: separate big .cs file into small .cs files

2. Reuse of cs files, namespace, arch advice pls

3. Soliciting views on PLs in CS education

4. Newbie: pls help with SendMessage

5. getchar() : newbie question, pls HELP

6. Pls help newbie: BITMAP Display

7. pls help a newbie with stupid string

8. C Newbie...pls help

9. Font listings - help for a newbie pls?

10. Newbie Pls. Help

11. expert advice needed pls, pls, pls

12. Newbie porting EventSample.cs to ASP.NET

 

 
Powered by phpBB® Forum Software