www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1997/02/25/01:23:02

From: "John M. Aldrich" <fighteer AT cs DOT com>
Newsgroups: comp.os.msdos.djgpp
Subject: Re: QUESTION: General Syntax
Date: Mon, 24 Feb 1997 23:47:41 -0800
Organization: Two pounds of chaos and a pinch of salt
Lines: 56
Message-ID: <3312991D.3983@cs.com>
References: <Pine DOT SOL DOT 3 DOT 91 DOT 970224190743 DOT 3403A-100000 AT world DOT evansville DOT net>
Reply-To: fighteer AT cs DOT com
NNTP-Posting-Host: ppp225.cs.com
Mime-Version: 1.0
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp

Zaphod Beeblebrox wrote:
> 
> I'm still really new to C/C++, but I was on a good steady track using the
> Personal C Compiler from C WARE.  The general syntax I'm used to doesn't
> apply in GCC.  Here is what I'm used to:

On the contrary, gcc uses exact ANSI C syntax.  The only things that are
different from other compilers are some of the non-ANSI functions and
the compiler-specific extensions.  You, however, must first supply
correct code.  There's an old rule:  "garbage in, garbage out."  :)

> main();
        ^
Take off that semicolon and the compiler will be much happier.  It's
even happier than that when you explicitly define main to return int,
but that's optional in C.  In C++, you _must_ explicitly define main()'s
return type.

> {
> puts("Hello World.");

puts is declared in the <stdio.h> header file.  You forgot to #include
it.

> return(0);
> }
 
Here's a tip for you that will stand you in good stead when compiling
programs:  always put the '-Wall' switch on gcc's command line.  That
makes the compiler give you lots of useful warnings about bad things you
might be doing, such as forgetting to include header files.

> Why won't this compile?  I get an unusual parser error at the first {.
> How do I fix this?  I know this will be an easy one to answer, but I've
> been hard at work looking for resources that cover the GCC Standard
> Syntax, and I can't find any.  So if you could point me to some, I'd be
> eternally grateful.  Thanks!

There ain't no such thing as "GCC standard syntax."  C is C is C, no
matter what compiler you are using.  If your compiler refuses to accept
correct ANSI C code, then it's time to get another.  Any half-decent
book or tutorial will tell you how to write basic programs; it's only
when you get into compiler-specific stuff like graphics that you have
trouble.

Once you are a little more experienced with C, try downloading and
reading the DJGPP Frequently Asked Questions list (v2/faq210b.zip from
SimTel).  It discusses all that "compiler-specific" stuff.  :)

-- 
---------------------------------------------------------------------
| John M. Aldrich, aka Fighteer I  |        fighteer AT cs DOT com         |
|    *  Proud user of DJGPP!  *    |   http://www.cs.com/fighteer   |
|    ObJoke:  If Bill Gates were a robber, not only would he        |
|     shoot you, but he'd send you a bill for the bullets.          |
---------------------------------------------------------------------

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019