www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1998/08/12/07:33:43

From: year2000uk AT my-dejanews DOT com
Newsgroups: comp.os.msdos.djgpp
Subject: Re: A very basic question about C programming... diary of a newbie Part 1
Date: Wed, 12 Aug 1998 11:06:31 GMT
Organization: Deja News - The Leader in Internet Discussion
Lines: 63
Message-ID: <6qrsvn$snf$1@nnrp1.dejanews.com>
References: <SS9A1.434$vq2 DOT 881313 AT newse2 DOT tampabay DOT rr DOT com>
NNTP-Posting-Host: 152.173.174.186
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp

In article <SS9A1.434$vq2 DOT 881313 AT newse2 DOT tampabay DOT rr DOT com>,
  "DM" <dragonmagikus AT no DOT no> wrote:
[snipped lots all over]
>
> So my question is... writing the word "void" before a function is how you
> prototype???
>
> Or, if you "declare" the function before the main() is that prototyping?

Simply declare it anywhere.  Typically though prototypes are placed near the
top of C source files, or in header files.

>
> If the void is it, what if the function has to return a value? Can you not
> prototype it then?

It doesn't have to be void, parameters or return value.  Here are some
examples:

void func0( void ) ;
void func1( int x ) ;
void func2( int x, char * text ) ;
void func3( int x, char y, double z ) ;
int func4( void ) ;
int func5( int a, int b, int c ) ;
double func6( char f. int g, char h ) ;

>
> I have the general idea, but I think the exact definition of exactly what to
> type is slighty vague in the tutorial.
>
> Can anyone enlighten me with a good definition of prototyping?

I'm sure there's a good one in a book someplace.
But the basic purpose is to declare definitions for function parameters and
return values.  The reason to do this, is it allows
1. TYPE SAFE (i.e. compiler checks parameters match) INTER-MODULE (between
different .c source files) funciton calls,
and
2. TYPE SAFE INTRA-MODULE (same source file) function calls. In the INTRA-
MODULE case, it's normally only necessary for declarations of functions whose
body is later in the file,e.g.

void bar( int x ) ; /* prototype for bar */

int foo( char a, char b )
{
  /* Body of foo, including a call to bar */
}

void bar( int x )
{
  /* Body of bar */
}



--
Y2K Made Easy - Compliance Information on 20,000 products -
http://www.ans2000.com

-----== Posted via Deja News, The Leader in Internet Discussion ==-----
http://www.dejanews.com/rg_mkgrp.xp   Create Your Own Free Member Forum

- Raw text -


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