www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1998/08/14/00:45:35

Message-ID: <35D3BD89.AF9C519B@geocities.com>
From: Merlin <merlin__ AT geocities DOT com>
MIME-Version: 1.0
Newsgroups: comp.os.msdos.djgpp
Subject: Re: A very basic question about C programming... diary of a newbie Part 1
References: <199808131109 DOT NAA15641 AT acp3bf DOT physik DOT rwth-aachen DOT de>
Lines: 55
Date: Fri, 14 Aug 1998 04:34:13 GMT
NNTP-Posting-Host: 228-cy-wpg.ilos.net
NNTP-Posting-Date: Thu, 13 Aug 1998 23:34:13 CDT
Organization: MBnet Networking Inc.
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp


Hans-Bernhard Broeker wrote:

> In article <35D2A017 DOT 4808178C AT geocities DOT com> you wrote:
>
> > Eli Zaretskii wrote:
>
> > > On Wed, 12 Aug 1998, Merlin wrote:
> > >
> > > > void do_nothing();     //these are prototypes
> > >
> > > No, this isn't a prototype.  This is:
> > >
> > >   void do_nothing(void);
>
> >   if you leave the void in brackets out it will be assumed..
>
> Wrong. In C, leaving out the argument list completely means you just
> wrote an 'old-style' (i.e.: K&R) function declaration, not a
> prototype. In detail, it does *not* define the function to take no
> arguments at all, it simply doesn't tell anything about the arguments.
> That means:
>
>         void do_nothing();
>
>         int main(void) {
>           do_nothing(235);
>           return 0;
>         }
>
>         void do_nothing(foo)
>           int foo;
>         {
>            foo = foo + foo;
>         }
>
> is a valid, correct ANSI-C program. It compiles, links and even works
> without any problem or warning message with 'gcc -ansi -pedantic -Wall
> -W -g -O'. Change the first line to 'void do_nothing(void);', and gcc
> won't even compile it any longer.
>

sorry..my mistake...

> C++ is a different case: there '()' means '(void)', which itself is
> *illegal*. At least, that's what my lossy memory tells me.

but in c++ if '()' means '(void)' then wouldn't '()' = '(void)' and
therfore the prototype be right?..

l8r,
    Merlin.


- Raw text -


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