Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > Function prototypes

Reply
Thread Tools

Function prototypes

 
 
Steph Barklay
Guest
Posts: n/a
 
      08-22-2007
Hi, I'm currently taking a data structures course in C, and my teacher
said that function prototypes are not allowed in any of our code. He
also said that no professional programmers use function prototypes. This
kind of bugged me, because from other people's code that I've seen in
the past, almost all of them use function prototypes. The following also
bugged me. Let's say you have a file called main.c with only the main
function, and includes hello.h, to use functions within hello.c. So
hello.h should contain prototypes for the functions in hello.c, so when
main.c is compiled, there won't be any warnings. If there aren't any
prototypes in the header file, my compiler would assume the function
called with main() is extern and returns an int. I tried to explain this
to my teacher, but the answer he gave me is that I should just put the
whole function within the header file and not have any other *.c files.
I haven't seen anyone put whole functions within header files before. Am
I wrong about this or is my teacher wrong? Thank you.

 
Reply With Quote
 
 
 
 
Al Balmer
Guest
Posts: n/a
 
      08-22-2007
On Thu, 23 Aug 2007 01:12:41 +0200 (CEST), Steph Barklay
<(E-Mail Removed)> wrote:

>Hi, I'm currently taking a data structures course in C, and my teacher
>said that function prototypes are not allowed in any of our code. He
>also said that no professional programmers use function prototypes. This
>kind of bugged me, because from other people's code that I've seen in
>the past, almost all of them use function prototypes. The following also
>bugged me. Let's say you have a file called main.c with only the main
>function, and includes hello.h, to use functions within hello.c. So
>hello.h should contain prototypes for the functions in hello.c, so when
>main.c is compiled, there won't be any warnings. If there aren't any
>prototypes in the header file, my compiler would assume the function
>called with main() is extern and returns an int. I tried to explain this
>to my teacher, but the answer he gave me is that I should just put the
>whole function within the header file and not have any other *.c files.
>I haven't seen anyone put whole functions within header files before. Am
>I wrong about this or is my teacher wrong? Thank you.


Is this for real? I find it hard to believe that any such teacher
exists. If this is not a troll, you should, if at all possible, enroll
in another class with a different teacher. If this is not possible,
ask your teacher to monitor this newsgroup for a while.

If that doesn't work, I don't know what to suggest. Probably you
should drop the course, and study C on your own.

--
Al Balmer
Sun City, AZ
 
Reply With Quote
 
 
 
 
Richard Heathfield
Guest
Posts: n/a
 
      08-22-2007
Steph Barklay said:

> Hi, I'm currently taking a data structures course in C, and my teacher
> said that function prototypes are not allowed in any of our code.


If he is being paid to teach you C, sue him.

> He
> also said that no professional programmers use function prototypes.


He is mistaken. Only fools (and those forced to use compilers so ancient
that you can hardly see them through the accumulated dust, hair, and
topsoil) omit them.

> Let's say you have a file called main.c with only the main
> function, and includes hello.h, to use functions within hello.c. So
> hello.h should contain prototypes for the functions in hello.c, so
> when main.c is compiled, there won't be any warnings. If there aren't
> any prototypes in the header file, my compiler would assume the
> function called with main() is extern and returns an int. I tried to
> explain this to my teacher, but the answer he gave me is that I should
> just put the whole function within the header file and not have any
> other *.c files. I haven't seen anyone put whole functions within
> header files before. Am I wrong about this or is my teacher wrong?


Your teacher is 100% wrong, brain-dead, and beyond redemption. Only
fools put code in headers.

--
Richard Heathfield <http://www.cpax.org.uk>
Email: -www. +rjh@
Google users: <http://www.cpax.org.uk/prg/writings/googly.php>
"Usenet is a strange place" - dmr 29 July 1999
 
Reply With Quote
 
Old Wolf
Guest
Posts: n/a
 
      08-22-2007
On Aug 23, 11:40 am, Richard Heathfield <(E-Mail Removed)> wrote:
> Your teacher is 100% wrong, brain-dead, and beyond redemption. Only
> fools put code in headers.


Only fools and C++ programmers

 
Reply With Quote
 
Keith Thompson
Guest
Posts: n/a
 
      08-22-2007
Steph Barklay <(E-Mail Removed)> writes:
> Hi, I'm currently taking a data structures course in C, and my teacher
> said that function prototypes are not allowed in any of our code. He
> also said that no professional programmers use function prototypes. This
> kind of bugged me, because from other people's code that I've seen in
> the past, almost all of them use function prototypes. The following also
> bugged me. Let's say you have a file called main.c with only the main
> function, and includes hello.h, to use functions within hello.c. So
> hello.h should contain prototypes for the functions in hello.c, so when
> main.c is compiled, there won't be any warnings. If there aren't any
> prototypes in the header file, my compiler would assume the function
> called with main() is extern and returns an int. I tried to explain this
> to my teacher, but the answer he gave me is that I should just put the
> whole function within the header file and not have any other *.c files.
> I haven't seen anyone put whole functions within header files before. Am
> I wrong about this or is my teacher wrong? Thank you.


Your teacher is very very very very very wrong.

Ask him to explain section 4.5 of K&R2 (that's Kernighan & Ritchie,
_The C Programming Language_, 2nd Edition) (it starts on page 81),
which absolutely contradicts your teacher's claims.

--
Keith Thompson (The_Other_Keith) http://www.velocityreviews.com/forums/(E-Mail Removed) <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
 
Reply With Quote
 
Richard Heathfield
Guest
Posts: n/a
 
      08-23-2007
Old Wolf said:

> On Aug 23, 11:40 am, Richard Heathfield <(E-Mail Removed)> wrote:
>> Your teacher is 100% wrong, brain-dead, and beyond redemption. Only
>> fools put code in headers.

>
> Only fools and C++ programmers


But you repeat yourself.

--
Richard Heathfield <http://www.cpax.org.uk>
Email: -www. +rjh@
Google users: <http://www.cpax.org.uk/prg/writings/googly.php>
"Usenet is a strange place" - dmr 29 July 1999
 
Reply With Quote
 
user923005
Guest
Posts: n/a
 
      08-23-2007
On Aug 22, 4:12 pm, Steph Barklay <(E-Mail Removed)> wrote:
> Hi, I'm currently taking a data structures course in C, and my teacher
> said that function prototypes are not allowed in any of our code. He
> also said that no professional programmers use function prototypes. This
> kind of bugged me, because from other people's code that I've seen in
> the past, almost all of them use function prototypes. The following also
> bugged me. Let's say you have a file called main.c with only the main
> function, and includes hello.h, to use functions within hello.c. So
> hello.h should contain prototypes for the functions in hello.c, so when
> main.c is compiled, there won't be any warnings. If there aren't any
> prototypes in the header file, my compiler would assume the function
> called with main() is extern and returns an int. I tried to explain this
> to my teacher, but the answer he gave me is that I should just put the
> whole function within the header file and not have any other *.c files.
> I haven't seen anyone put whole functions within header files before. Am
> I wrong about this or is my teacher wrong? Thank you.


Your teacher is criminally insane. Notify the authorities right away.

On the other hand, this is my evil handiwork:

#ifdef _MSC_VER
#include <windows.h>
#else
#include <unistd.h>
#endif

#include "searchr.c"
#include "search.c"
#include "thread.c"
#include "searchmp.c"
#include "repeat.c"
#include "next.c"
#include "nexte.c"
#include "nextr.c"
#include "history.c"
#include "quiesce.c"
#include "evaluate.c"
#include "movgen.c"
#include "make.c"
#include "unmake.c"
#include "hash.c"
#include "attacks.c"
#include "swap.c"
#include "boolean.c"
#include "utility.c"
#include "valid.c"
#include "probe.c"
#include "book.c"
#include "analyze.c"
#include "annotate.c"
#include "bench.c"
#include "data.c"
#ifndef _MSC_VER
#include "dgt.c"
#endif
#include "drawn.c"
#include "edit.c"
#include "epd.c"
#include "epdglue.c"
#include "evtest.c"
#include "init.c"
#include "input.c"
#include "interupt.c"
#include "iterate.c"
#include "learn.c"
#include "main.c"
#include "option.c"
#include "output.c"
#include "ponder.c"
#include "preeval.c"
#include "resign.c"
#include "root.c"
#include "setboard.c"
#include "test.c"
#include "time.c"
#include "validate.c"

On the other hand, each of those files has headers with prototypes and
there are headers with prototypes at the top even of this file.
Some compilers can inline more aggressively if you make every file
available as a single giant block of source code.


 
Reply With Quote
 
Stephen Sprunk
Guest
Posts: n/a
 
      08-23-2007
"Richard Heathfield" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> Your teacher is 100% wrong, brain-dead, and beyond redemption.
> Only fools put code in headers.


99% wrong; there are valid reasons for code in headers, such as
function-like macros or static inline functions. However, I doubt that the
teacher was thinking about those things.

S

--
Stephen Sprunk "God does not play dice." --Albert Einstein
CCIE #3723 "God is an inveterate gambler, and He throws the
K5SSS dice at every possible opportunity." --Stephen Hawking


--
Posted via a free Usenet account from http://www.teranews.com

 
Reply With Quote
 
CBFalconer
Guest
Posts: n/a
 
      08-23-2007
Steph Barklay wrote:
>
> Hi, I'm currently taking a data structures course in C, and my teacher
> said that function prototypes are not allowed in any of our code. He
> also said that no professional programmers use function prototypes. This
> kind of bugged me, because from other people's code that I've seen in
> the past, almost all of them use function prototypes. The following also
> bugged me. Let's say you have a file called main.c with only the main
> function, and includes hello.h, to use functions within hello.c. So
> hello.h should contain prototypes for the functions in hello.c, so when
> main.c is compiled, there won't be any warnings. If there aren't any
> prototypes in the header file, my compiler would assume the function
> called with main() is extern and returns an int. I tried to explain this
> to my teacher, but the answer he gave me is that I should just put the
> whole function within the header file and not have any other *.c files.
> I haven't seen anyone put whole functions within header files before. Am
> I wrong about this or is my teacher wrong? Thank you.


Either the teacher, or your interpretation of his words, are
totally balmy.

--
Chuck F (cbfalconer at maineline dot net)
Available for consulting/temporary embedded and systems.
<http://cbfalconer.home.att.net>



--
Posted via a free Usenet account from http://www.teranews.com

 
Reply With Quote
 
Eric Sosman
Guest
Posts: n/a
 
      08-23-2007
Steph Barklay wrote:
> Hi, I'm currently taking a data structures course in C, and my teacher
> said that function prototypes are not allowed in any of our code. He
> also said that no professional programmers use function prototypes.
> [...]


Two possibilities occur to me. First, you may have
misunderstood what the teacher said (the blame for this
could lie on either side, or on both). It would be a
good idea to discuss this matter with the teacher to clear
up any possible misunderstanding.

Second, you may not have misunderstood at all, and
the teacher may actually have made this assertion. If so,
I recommend you drop the course: a teacher who utters this
sort of nonsense (other than as a pedagogic device intended
to elicit push-back, which really falls under Possibility 1)
is ignorant of his or her subject. This person may be able
to teach you something useful, but will teach you a lot of
nonsense along with it and leave you the task of separating
the one from the other unassisted.

--
Eric Sosman
(E-Mail Removed)lid
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
function prototypes and function addresses Syren Baran C Programming 6 01-09-2008 06:34 PM
Re: Can function prototypes appear anywhere? Lawrence Kirby C Programming 2 01-24-2005 04:56 PM
Re: Can function prototypes appear anywhere? Chris Dollin C Programming 3 01-19-2005 06:01 PM
order of const in function prototypes Denis Remezov C++ 7 06-30-2004 11:41 AM
New to Python; what about #include, extern and function prototypes Bo Jacobsen Python 6 03-07-2004 02:37 PM



Advertisments