Function prototypes

K

Kenneth Brody

Richard said:
Steph Barklay said: [...]
8. At the top of the main source file, a narrative must be included
that describes the purpose of the program, who was the principle
programmer on the programming team. If the program went through

You'd think a teacher would know the difference between "principle" and
"principal", wouldn't you?
[...]

Just on principle, you should report him to the principal.

--
+-------------------------+--------------------+-----------------------+
| Kenneth J. Brody | www.hvcomputer.com | #include |
| kenbrody/at\spamcop.net | www.fptech.com | <std_disclaimer.h> |
+-------------------------+--------------------+-----------------------+
Don't e-mail me at: <mailto:[email protected]>
 
K

Kenneth Brody

Eric said:
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>
[...]
return 0;
}

Alas, the constant in the `return' statement is not
in upper case.

It looks like a capital zero to me.
Suggested fix:

typedef { TRUE, FALSE } Boolean;
...
return TRUE;

;-)

(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 ...)

Sorry, but your capitalization of "Boolean" probably breaks some
other "rule".

--
+-------------------------+--------------------+-----------------------+
| Kenneth J. Brody | www.hvcomputer.com | #include |
| kenbrody/at\spamcop.net | www.fptech.com | <std_disclaimer.h> |
+-------------------------+--------------------+-----------------------+
Don't e-mail me at: <mailto:[email protected]>
 
P

pete

Charlton said:
it sounds like what he really wants is all the code for the
assignments to be in one file, with all the functions preceding the
main() function at the end of the file, and with no mutual recursion.

There's nothing wrong with that.

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

Keith Thompson

CBFalconer said:
[...]
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.
 
K

Keith Thompson

CBFalconer said:
Steph said:
I dont think I misunderstood, here are the course guidelines quite
clear about this.

"During this semester, all programs submitted for homework or extra
credit and the project must conform to the following programming
standards: [snip]
5. Use of function prototypes is prohibited. As such, all functions
must appear in reverse order of use, with the function main() being
the last function in the program.
[snip]

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?
The history has been lost by the unnecessary top-posting.

Top-posting has caused some confusion, but the real source of
confusion is the instructor's incorrectly stated requirements. It's
very likely that he didn't actually intend to ban all prototypes, but
that's exactly what he said.

If the instructor had stated what he actually meant (no prototypes in
your own code other than as part of a full function definition), it
would be a reasonable requirements for a small assignment that fits in
one source file. Forcing students to use a consistent orderering
(functions defined after anything they call, main at the end) is not
an unreasable style, and probably makes it easier for the instructor
to read the dozens of programs he's going to have to grade. (I'm
ignoring rule 9 regarding include files.)

Of course once the students start writing multi-file programs, proper
headers with prototypes should be mandatory.

The instructor has been quoted as saying that professional programmers
don't use prototypes; I can't think of a resaonable interpretation of
such a statement.
 
R

Richard Tobin

Keith Thompson said:
If the instructor had stated what he actually meant (no prototypes in
your own code other than as part of a full function definition), it
would be a reasonable requirements for a small assignment that fits in
one source file. Forcing students to use a consistent orderering
(functions defined after anything they call, main at the end) is not
an unreasable style,

I disagree, but even if it were good style it prevents the use of
mutually recursive functions.

-- Richard
 
C

Charlton Wilbur

p> It was OP's second statement which was inflammatory: "Hi, I'm
p> currently taking a data structures course in C, and my teacher
p> said that function prototypes are not allowed in any of our
p> code. He also said that no professional programmers use
p> 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.

Charlton
 
J

Joe Wright

Keith said:
CBFalconer said:
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.

As to function prototypes, they are a godsend. They tell the compiler
how to call the function such that the compiler may do some conversions
to make things happen as expected. Consider..

int i = sqrt(2);

...without a prototype for sqrt() in scope, the compiler will call the
sqrt function with a integer (2) and accept its return as an int.

including <math.h> will provide a prototype like..

double sqrt(double);

...which tells the compiler that sqrt takes a double so it will convert 2
to 2.0 while calling the function.
 
B

Ben Pfaff

Joe Wright said:
Keith said:
CBFalconer said:
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).
 
R

Richard Heathfield

Joe Wright said:
Keith said:
CBFalconer said:
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>
 
J

Joe Wright

Richard said:
Joe Wright said:
Keith said:
[...]
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.
 
J

Joe Wright

Ben said:
Joe Wright said:
Keith said:
[...]
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?
 
C

CBFalconer

Keith said:
CBFalconer said:
Steph said:
I dont think I misunderstood, here are the course guidelines quite
clear about this.

"During this semester, all programs submitted for homework or extra
credit and the project must conform to the following programming
standards:
[snip]
5. Use of function prototypes is prohibited. As such, all functions
must appear in reverse order of use, with the function main() being
the last function in the program.
[snip]

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.

.... snip ...
The instructor has been quoted as saying that professional programmers
don't use prototypes; I can't think of a resaonable interpretation of
such a statement.

Agreed.
 
C

CBFalconer

Keith said:
[...]
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 :)
 
B

Barry Schwarz

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
 
S

Stephen Sprunk

CBFalconer said:
Keith said:
[...]
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
 
C

CBFalconer

Barry said:
.... 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.
 
C

Chris Dollin

Richard said:
I disagree, but even if it were good style it prevents the use of
mutually recursive functions.

It's /possible/ that the instructor knows that, and is currently
presenting problems for which the natural C solutions don't
involve mutual recursion (or recursion at all); when that
topic comes up, they can then retract the prohibition.
 

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,997
Messages
2,570,241
Members
46,831
Latest member
RusselWill

Latest Threads

Top