Function prototypes

S

Steph Barklay

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.
 
A

Al Balmer

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.
 
R

Richard Heathfield

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.
 
K

Keith Thompson

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. 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.
 
U

user923005

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.
 
S

Stephen Sprunk

Richard Heathfield said:
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
 
C

CBFalconer

Steph 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. 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.
 
E

Eric Sosman

Steph 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. 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.
 
P

pete

Steph 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. He
also said that no professional programmers use function prototypes.

That implies, or very nearly implies,
that professional programmers don't write C programs
with more than one file of source code.

It also suggests that your teacher has never
written a C program with more than one file of source code,
and thus is a neophyte programmer.
How old is this kid?

I hope that you're mistaken about what he said.
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
No.

or is my teacher wrong?

He absolutely does not understand what header files are for,
and is giving very strong indications
that he has no experience with multifile C programs.
Thank you.

Again, I very much hope that you have misunderstood what he meant.
 
O

osmium

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. 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 instructor is pathetic. He is talking about little toy programs, the
kind you write in the very class you are enrolled in. My guess is that he
has never seen the code for a real program in his entire life.
 
A

Army1987

Your instructor is pathetic. He is talking about little toy programs, the
kind you write in the very class you are enrolled in. My guess is that he
has never seen the code for a real program in his entire life.
I can't see any use in doing so in even the smallest program. (If
a program is *really* a little toy program, there is no real
reason to split it across several source files, either, unless to
teach how that is done; but I think that teaching to do that badly
is worse that not to teach it at all.)
 
A

Army1987

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" [snip enormous list]
#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.
At least their name ends with .c, so that one will know that extra
care shall be taken not to define anything twice.
 
R

Ravishankar S

#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"
Some compilers can inline more aggressively if you make every file
available as a single giant block of source code.

just a little off topic:
Would the compilation also be faster if all headers were included in a gaint
header file ?
 
O

osmium

I can't see any use in doing so in even the smallest program. (If
a program is *really* a little toy program, there is no real
reason to split it across several source files, either, unless to
teach how that is done; but I think that teaching to do that badly
is worse that not to teach it at all.)

I almost always write such programs "Pascal style", which obviates the
prototypes. If I change something involving function calls, there is only
one place to change. If such a program grew to a substantial size, and
drifted from the original intent, I might reorganize the code to "C style",
with prototypes, I think the documentation flows better that way, especially
for someone new to the code.
 
R

Richard Heathfield

osmium said:

I almost always write such programs "Pascal style", which obviates the
prototypes.

No, not really. A prototype is a function declaration that lists the
types of its parameters. For function definitions /not/ to do this,
they must either be written K&R style or with empty parentheses. Both
of these styles are very rare nowadays. It is almost certain that you
are in fact using prototypes, even when programming "Pascal style".

<snip>
 
O

osmium

Richard Heathfield said:
osmium said:



No, not really. A prototype is a function declaration that lists the
types of its parameters. For function definitions /not/ to do this,
they must either be written K&R style or with empty parentheses. Both
of these styles are very rare nowadays. It is almost certain that you
are in fact using prototypes, even when programming "Pascal style".

As you should know by now, I am not a big fan of using word games in
discussions involving newbies.
 
R

Richard Heathfield

osmium said:
As you should know by now, I am not a big fan of using word games in
discussions involving newbies.

As you should know by now, using proper terminology in the proper way is
not a matter of word games, but a matter of correctness.
 
R

Richard

osmium said:
As you should know by now, I am not a big fan of using word games in
discussions involving newbies.

And as you should know, *any* thread that Mr Heathfield contributes to
descends to just that.

I still his recall "there is no such thing as a global variable in C" blather.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top