By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
449,034 Members | 1,012 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 449,034 IT Pros & Developers. It's quick & easy.

Function prototypes

P: n/a
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.

Aug 22 '07
Share this Question
Share on Google+
73 Replies


P: n/a
Joe Wright <jo********@comcast.netwrites:
Keith Thompson wrote:
>CBFalconer <cb********@yahoo.comwrites:
[...]
>>>>>>3. All constants must be in uppercase
[...]
>>Quibble: All the digits are already upper case, no lower case digit
exists.

Meta-quibble: Digits are neither upper case nor lower case.
isupper('5') and islower('5') both return 0.
Watta ya wanna bet? isupper() and islower() treat only isalpha()
values. Just a guess. I haven't looked it up.
Then why are you arguing with someone who knows what he's talking
about?

7.4.1.11 The isupper function
Synopsis
1 #include <ctype.h>
int isupper(int c);
Description
2 The isupper function tests for any character that is an
uppercase letter or is one of a locale-specific set of
characters for which none of iscntrl, isdigit, ispunct, or
isspace is true. In the "C" locale, isupper returns true
only for the uppercase letters (as defined in 5.2.1).

--
"In My Egotistical Opinion, most people's C programs should be indented six
feet downward and covered with dirt." -- Blair P. Houghton
Aug 25 '07 #51

P: n/a
Richard Heathfield wrote:
Joe Wright said:
>Keith Thompson wrote:
>>CBFalconer <cb********@yahoo.comwrites:
[...]
>>>3. All constants must be in uppercase
[...]
Quibble: All the digits are already upper case, no lower case digit
exists.
Meta-quibble: Digits are neither upper case nor lower case.
isupper('5') and islower('5') both return 0.
Watta ya wanna bet?

The farm.
>isupper() and islower() treat only isalpha()
values. Just a guess. I haven't looked it up.

I have (although I knew it already - but where a bet is concerned, I
look it up anyway). Both isupper and islower are required to return 0
for digit characters.

You owe me a farm.

<snip>
For the life of me, I know not where "Watta ya wanna bet?" came from.
Clearly isupper('5') and islower('5') both return 0.

I'll have to owe you the farm. I don't have one at present.

--
Joe Wright
"Everything should be made as simple as possible, but not simpler."
--- Albert Einstein ---
Aug 25 '07 #52

P: n/a
Ben Pfaff wrote:
Joe Wright <jo********@comcast.netwrites:
>Keith Thompson wrote:
>>CBFalconer <cb********@yahoo.comwrites:
[...]
>>>3. All constants must be in uppercase
[...]
Quibble: All the digits are already upper case, no lower case digit
exists.
Meta-quibble: Digits are neither upper case nor lower case.
isupper('5') and islower('5') both return 0.
Watta ya wanna bet? isupper() and islower() treat only isalpha()
values. Just a guess. I haven't looked it up.

Then why are you arguing with someone who knows what he's talking
about?

7.4.1.11 The isupper function
Synopsis
1 #include <ctype.h>
int isupper(int c);
Description
2 The isupper function tests for any character that is an
uppercase letter or is one of a locale-specific set of
characters for which none of iscntrl, isdigit, ispunct, or
isspace is true. In the "C" locale, isupper returns true
only for the uppercase letters (as defined in 5.2.1).
Brain fart maybe. I didn't really argue against the point. Now that I'm
looking at it, I don't know what "Watta ya wanna bet?" meant. Apparently
it's cost me a farm already. :-)

Stanford is "The Farm" isn't it? Can you help me out?

--
Joe Wright
"Everything should be made as simple as possible, but not simpler."
--- Albert Einstein ---
Aug 25 '07 #53

P: n/a
Keith Thompson wrote:
CBFalconer <cb********@yahoo.comwrites:

[...]
>>>>>3. All constants must be in uppercase
[...]
>Quibble: All the digits are already upper case, no lower case
digit exists.

Meta-quibble: Digits are neither upper case nor lower case.
isupper('5') and islower('5') both return 0.
Yabut silly requibble: toupper('6') returns '6', must be upper :-)

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

Aug 26 '07 #54

P: n/a
On Thu, 23 Aug 2007 01:12:41 +0200 (CEST), Steph Barklay
<do**@spam.mewrote:
>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.
You might ask him what all those prototypes are doing in the standard
headers.

I wonder if he is an ex-Pascal junkie where you had to define
functions prior to their use.
Remove del for email
Aug 26 '07 #55

P: n/a
"CBFalconer" <cb********@yahoo.comwrote in message
news:46***************@yahoo.com...
Keith Thompson wrote:
>CBFalconer <cb********@yahoo.comwrites:

[...]
>>>>>>3. All constants must be in uppercase
[...]
>>Quibble: All the digits are already upper case, no lower case
digit exists.

Meta-quibble: Digits are neither upper case nor lower case.
isupper('5') and islower('5') both return 0.

Yabut silly requibble: toupper('6') returns '6', must be upper :-)
tolower('6') returns '6', must be lower :-)

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

Aug 26 '07 #56

P: n/a
Barry Schwarz wrote:
>
.... snip ...
>
I wonder if he is an ex-Pascal junkie where you had to define
functions prior to their use.
Same thing in C, with the added ability to use prototypes and take
advantage of the default provisions. In place of prototypes Pascal
has the forward declaration.

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

Aug 26 '07 #57

P: n/a
On Fri, 24 Aug 2007 11:10:55 +0000, Richard Heathfield wrote:
Army1987 said:
>On Fri, 24 Aug 2007 01:23:37 +0000, Richard Heathfield wrote:
>>>3. All constants must be in uppercase

This is unusual. It would mean that you couldn't write a program to
print this sentence, since you'd have to use "PROGRAM", say, rather
than "program" (string literals are constants).

#include <stdio.h>
#include <ctype.h>
int main(void)
{
char *s1 = "T WOULD MEAN THAT YOU COULDN'T WRITE A PROGRAM "
"TO PRINT THIS SENTENCE, SINCE YOU'D HAVE TO USE ";
char *s2 = ", SAY, RATHER THAN \"PROGRAM\" (STRING LITERALS "
"ARE CONSTANTS).";
putchar('I');
while (*s1) putchar(tolower(*s1++));

Very good. But alas! You used a function prototype! :-)
Whoops...
Remove the headers and 'void'. :-)

--
Army1987 (Replace "NOSPAM" with "email")
No-one ever won a game by resigning. -- S. Tartakower

Aug 26 '07 #58

P: n/a
On Sun, 26 Aug 2007 12:31:29 +0200, Army1987 wrote:
On Fri, 24 Aug 2007 11:10:55 +0000, Richard Heathfield wrote:
>Army1987 said:
>>#include <stdio.h>
#include <ctype.h>
int main(void)
{
char *s1 = "T WOULD MEAN THAT YOU COULDN'T WRITE A PROGRAM "
"TO PRINT THIS SENTENCE, SINCE YOU'D HAVE TO USE ";
char *s2 = ", SAY, RATHER THAN \"PROGRAM\" (STRING LITERALS "
"ARE CONSTANTS).";
putchar('I');
while (*s1) putchar(tolower(*s1++));

Very good. But alas! You used a function prototype! :-)
Whoops...
Remove the headers and 'void'. :-)
And replace printf() with another few putchar()s...
--
Army1987 (Replace "NOSPAM" with "email")
No-one ever won a game by resigning. -- S. Tartakower

Aug 26 '07 #59

P: n/a
Richard Heathfield wrote:
Joe Wright said:
>Keith Thompson wrote:
>>CBFalconer <cb********@yahoo.comwrites:
[...]
>>>3. All constants must be in uppercase
[...]
Quibble: All the digits are already upper case, no lower case digit
exists.
Meta-quibble: Digits are neither upper case nor lower case.
isupper('5') and islower('5') both return 0.
Watta ya wanna bet?

The farm.
>isupper() and islower() treat only isalpha()
values. Just a guess. I haven't looked it up.

I have (although I knew it already - but where a bet is concerned, I
look it up anyway). Both isupper and islower are required to return 0
for digit characters.

You owe me a farm.
Joe's agent is an old geezer named MacDonald ...

--
Eric Sosman
es*****@ieee-dot-org.invalid
Aug 26 '07 #60

P: n/a
Charlton Wilbur wrote:
>>>>>"p" == pete <pf*****@mindspring.comwrites:

pIt was OP's second statement which was inflammatory: "Hi, I'm
pcurrently taking a data structures course in C, and my teacher
psaid that function prototypes are not allowed in any of our
pcode. He also said that no professional programmers use
pfunction prototypes."

Right, but the only evidence we have of that is a student's say so;
and given the choice between a professor really being that
out-of-touch and a student misunderstanding, smart money's on the
student misunderstanding.
In a follow-up, the student provided a whole list of rules
and requirements. I tend to believe these were probably copied
verbatim from something the teacher handed out, and thus are a
reasonably accurate representation of the teacher's instructions.

The posted rules do not include the stupid remark about
professional programmers, but they do offer evidence that the
teacher does not know what a prototype is, or that if he does
he chooses to use sloppy and misleading language anyhow.

I'll bet you Richard's new farm that the teacher will
eventually also misuse the phrase "pointer to an array."

--
Eric Sosman
es*****@ieee-dot-org.invalid
Aug 26 '07 #61

P: n/a
Eric Sosman wrote:
Charlton Wilbur wrote:
>pete <pf*****@mindspring.comwrites:
>>It was OP's second statement which was inflammatory: "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."

Right, but the only evidence we have of that is a student's say
so; and given the choice between a professor really being that
out-of-touch and a student misunderstanding, smart money's on
the student misunderstanding.

In a follow-up, the student provided a whole list of rules
and requirements. I tend to believe these were probably copied
verbatim from something the teacher handed out, and thus are a
reasonably accurate representation of the teacher's instructions.

The posted rules do not include the stupid remark about
professional programmers, but they do offer evidence that the
teacher does not know what a prototype is, or that if he does
he chooses to use sloppy and misleading language anyhow.
Similarly, the posted full rules were never intended for c.l.c, but
for a collection of totally ignorant youthful students. For here,
it might have been worded much differently.

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

Aug 26 '07 #62

P: n/a
CBFalconer <cb********@yahoo.comwrites:
Keith Thompson wrote:
>CBFalconer <cb********@yahoo.comwrites:
[...]
>>That's quite reasonable for one-file programs, and with
modifications for all programs. It is not banning prototypes - it
is forcing proper organization of prototypeless source.

A requirement that "Use of function prototypes is prohibited" is not
banning prototype?

A proper function declaration/definition also creates a prototype,
with no separate lump of verbiage. Nothing to ensure matching
with, etc. You just have to relax your normally more precise
verbiage, and put yourself in the position of the students and
instructor.
No, I really don't have to. The instructor is supposed to instruct;
misusing technical terms does not serve that purpose. I understand
what he meant (probably), but it's up to him to actually say what he
means (and it's not that difficult).

--
Keith Thompson (The_Other_Keith) ks***@mib.org <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"
Aug 27 '07 #63

P: n/a
CBFalconer <cb********@yahoo.comwrites:
Eric Sosman wrote:
>Charlton Wilbur wrote:
>>pete <pf*****@mindspring.comwrites:

It was OP's second statement which was inflammatory: "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."

Right, but the only evidence we have of that is a student's say
so; and given the choice between a professor really being that
out-of-touch and a student misunderstanding, smart money's on
the student misunderstanding.

In a follow-up, the student provided a whole list of rules
and requirements. I tend to believe these were probably copied
verbatim from something the teacher handed out, and thus are a
reasonably accurate representation of the teacher's instructions.

The posted rules do not include the stupid remark about
professional programmers, but they do offer evidence that the
teacher does not know what a prototype is, or that if he does
he chooses to use sloppy and misleading language anyhow.

Similarly, the posted full rules were never intended for c.l.c, but
for a collection of totally ignorant youthful students. For here,
it might have been worded much differently.
And what would be wrong with using terms correctly in a handout
intended for ignorant students, so they won't have to unlearn anything
later on?

Some of them might not be all that ignorant. For example, some of
them just might post to comp.lang.c to find out what the instructor
really meant.

--
Keith Thompson (The_Other_Keith) ks***@mib.org <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"
Aug 27 '07 #64

P: n/a
Richard Bos wrote:
>
CBFalconer <cb********@yahoo.comwrote:
.... snip ...
>
>--
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

Nor do I find a double .sig logical.
It isn't. When it leaves here it has one. Teranews appends their
own marker.

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

Aug 27 '07 #65

P: n/a
Keith Thompson wrote:
>
CBFalconer <cb********@yahoo.comwrites:
[...]
Similarly, the posted full rules were never intended for c.l.c, but
for a collection of totally ignorant youthful students. For here,
it might have been worded much differently.

And what would be wrong with using terms correctly in a handout
intended for ignorant students, so they won't have to unlearn anything
later on?

Some of them might not be all that ignorant. For example, some of
them just might post to comp.lang.c to find out what the instructor
really meant.
Sure, but what are the odds of that happening?

--
+-------------------------+--------------------+-----------------------+
| Kenneth J. Brody | www.hvcomputer.com | #include |
| kenbrody/at\spamcop.net | www.fptech.com | <std_disclaimer.h|
+-------------------------+--------------------+-----------------------+
Don't e-mail me at: <mailto:Th*************@gmail.com>
Aug 27 '07 #66

P: n/a
Stephen Sprunk wrote:
>
"CBFalconer" <cb********@yahoo.comwrote in message
news:46***************@yahoo.com...
Keith Thompson wrote:
CBFalconer <cb********@yahoo.comwrites:

[...]
>3. All constants must be in uppercase
[...]

Quibble: All the digits are already upper case, no lower case
digit exists.

Meta-quibble: Digits are neither upper case nor lower case.
isupper('5') and islower('5') both return 0.
Yabut silly requibble: toupper('6') returns '6', must be upper :-)

tolower('6') returns '6', must be lower :-)
It's a Heisendigit(TM)[1][2], being both upper- and lowercase, and yet
neither.
[1] Hey, did I just coin a new word?
[2] Heisendigit is a trademark of Heisenbug Enterprises International.
All rights reserved. Lefts are available for rent. You have the
right to rent lefts, while simultaneously you have left your
rights to rent outside.

--
+-------------------------+--------------------+-----------------------+
| Kenneth J. Brody | www.hvcomputer.com | #include |
| kenbrody/at\spamcop.net | www.fptech.com | <std_disclaimer.h|
+-------------------------+--------------------+-----------------------+
Don't e-mail me at: <mailto:Th*************@gmail.com>
Aug 27 '07 #67

P: n/a
Kenneth Brody wrote, On 27/08/07 18:16:
Keith Thompson wrote:
>CBFalconer <cb********@yahoo.comwrites:
[...]
>>Similarly, the posted full rules were never intended for c.l.c, but
for a collection of totally ignorant youthful students. For here,
it might have been worded much differently.
And what would be wrong with using terms correctly in a handout
intended for ignorant students, so they won't have to unlearn anything
later on?

Some of them might not be all that ignorant. For example, some of
them just might post to comp.lang.c to find out what the instructor
really meant.

Sure, but what are the odds of that happening?
No idea, but it does happen because this thread was as a result of one
of the students posting here asking about it!
--
Flash Gordon
Aug 27 '07 #68

P: n/a
Groovy hepcat Eric Sosman was jivin' in comp.lang.c on Fri, 24 Aug 2007
11:32 am. It's a cool scene! Dig it.
Richard Heathfield wrote:
>[...]
You'd think a teacher would know the difference between "principle"
and "principal", wouldn't you?

I blam our flawhed eductaional sistym!
Yu dun mispelded "ejamakayshunnel". ;)

--
Dig the sig!

----------- Peter 'Shaggy' Haywood ------------
Ain't I'm a dawg!!
Aug 28 '07 #69

P: n/a
Ravishankar S wrote:
>#ifdef _MSC_VER
#include <windows.h>
#else
#include <unistd.h>
#endif

#include "searchr.c"
#include "search.c"
....snip...
>#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 ?
If you look close, you will see that these are NOT header
files. He is including SOURCE files.

His compiler must me missing a linker.

----== Posted via Newsfeeds.Com - Unlimited-Unrestricted-Secure Usenet News==----
http://www.newsfeeds.com The #1 Newsgroup Service in the World! 120,000+ Newsgroups
----= East and West-Coast Server Farms - Total Privacy via Encryption =----
Aug 28 '07 #70

P: n/a
Flash Gordon wrote:
>
Kenneth Brody wrote, On 27/08/07 18:16:
Keith Thompson wrote:
CBFalconer <cb********@yahoo.comwrites:
[...]
Some of them might not be all that ignorant. For example, some of
them just might post to comp.lang.c to find out what the instructor
really meant.
Sure, but what are the odds of that happening?

No idea, but it does happen because this thread was as a result of one
of the students posting here asking about it!
I guess I did need those smileys afterall. :-) :-)

--
+-------------------------+--------------------+-----------------------+
| Kenneth J. Brody | www.hvcomputer.com | #include |
| kenbrody/at\spamcop.net | www.fptech.com | <std_disclaimer.h|
+-------------------------+--------------------+-----------------------+
Don't e-mail me at: <mailto:Th*************@gmail.com>
Aug 28 '07 #71

P: n/a
On Fri, 24 Aug 2007 08:22:22 -0400, Eric Sosman
<es*****@ieee-dot-org.invalidwrote:
Army1987 wrote:
On Fri, 24 Aug 2007 01:23:37 +0000, Richard Heathfield wrote:
>3. All constants must be in uppercase
return 0;
Alas, the constant in the `return' statement is not
in upper case. Suggested fix:

typedef { TRUE, FALSE } Boolean;
...
return TRUE;
s/typedef/typedef enum/
;-)
Ditto.
(Disclaimer: I didn't invent the `typedef', but ran
across it years ago in somebody else's code. It made for
an interesting debugging session ...)
At least enumeratees are usually IN debug symbols. Macros, the other
popular way of doing this, (too) often aren't. Although, of course,
they can be as far as the Standard, and thus clc, cares.

Now if you have enum { TRUE, FALSE } in some source files -- either
directly, or by #include'ing one header -- and enum { FALSE, TRUE } in
some other sources -- perhaps from a different header, perhaps even a
header with the same (file)name but a different place in the directory
(perhaps network) hierarchy -- then you're in truly evil territory.

- formerly david.thompson1 || achar(64) || worldnet.att.net
Sep 9 '07 #72

P: n/a
On Thu, 23 Aug 2007 20:04:25 -0400, pete <pf*****@mindspring.com>
wrote:
<snip>
I was granting that he meant prototypes in source code.
(I think it's established later he(?) meant forward declarations.)
But if you take him literally to just mean
making use of prototypes in code, then yes,
I don't think you can write a program for a modern C implementation,
that has any output, without using prototypes.
putchar and puts, along with getchar and <ALARM! DON'T USE>gets, can
be correctly (enough) declared without protototypes and without the
type FILE (which officially you can't use without #include'ing
<stdio.hand thereby getting prototype declarations).

It's certainly more convenient to have *printf, but everything printf
or fprintf(stdout do _can_ be done "manually" with putchar.

It's more powerful to have fopen/fclose/etc., but not strictly
necessary to get some output.

- formerly david.thompson1 || achar(64) || worldnet.att.net
Sep 9 '07 #73

P: n/a
On Thu, 23 Aug 2007 14:28:14 -0700, "osmium" <r1********@comcast.net>
wrote:
"Keith Thompson" writes:
I see no word games here. The word "prototype" has a very specific
meaning, and it includes both standalone function declarations:
void func(int);
and full function definitions:
void func(int arg) { /* ... */ }
<snip>
Do you have some reason to assume that the original poster was using
the term in the same narrow sense in which you were using it?

Of course I have such a reason. The instructor's programs wouldn't work
otherwise, all he could do is write functions that returned an int or
returned nothing. I have already agreed the instructor shouldn't have said
what he said. What do you want, blood?
That's not a valid reason. The nonprototype aka oldstyle aka K&R1
syntax does allow you to declare any supported return type for a
function; it is only the _parameter_ types that are omitted, or for an
oldstyle definition serving as a declaration discarded.

I agree from the later full quote that the instructor _meant_ the
prohibition of "prototypes" to mean forward declarations, and thereby
to require bottom-up* layout. But that is in fact not the correct
meaning of prototype, and the correct meaning is important.

* often associated with Pascal although it is not actually required
there, and is permitted and encouraged in several other languages.

- formerly david.thompson1 || achar(64) || worldnet.att.net
Sep 9 '07 #74

73 Replies

This discussion thread is closed

Replies have been disabled for this discussion.