Function prototypes

E

Eric Sosman

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.

Joe's agent is an old geezer named MacDonald ...
 
E

Eric Sosman

Charlton said:
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.

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

CBFalconer

Eric said:
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.
 
K

Keith Thompson

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

Keith Thompson

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

Richard Bos

CBFalconer said:
Pure prototypes are not needed if you are not connecting to other
files, nor using some forms of recursion. Simply writing the code
in a logical order suffices.

FSVO "logical". I prefer to see main() first; I don't find a
minute-details-first order logical.

Nor do I find a double .sig logical.

Richard
 
K

Kenneth Brody

Stephen said:
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 :)

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:[email protected]>
 
K

Kenneth Brody

Keith said:
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:[email protected]>
 
F

Flash Gordon

Kenneth Brody wrote, On 27/08/07 18:16:
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!
 
P

Peter 'Shaggy' Haywood

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 said:
[...]
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". ;)
 
K

Kevin Handy

Ravishankar said:
....snip...


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

Kevin Handy

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:

1. Use of global variables is prohibited
2. All variables must be in lower case, with clear and concise names
that depict what data the varible will contain.
3. All constants must be in uppercase
4. Use of global constants, such as PI, is permitted
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.
6. Internal documentation for programs must include data range
specifications for each variable.
7. Before each function a short narrative must be included that
describes the purpose of the function, pre-conditions that must exist
for the function, what data the function returns and by what method
the data is returned, and who developed and programmed the function
which must, include email contact information..
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
several revisions, a revision history must be included.
9. If "include" files are used, each "include" file must conform to
items 1 to 8."

Are you sure that you haven't enrolled in a pascal class?

Either that, or you are being taught by a pascal programmer.
 
K

Kenneth Brody

Flash said:
Kenneth Brody wrote, On 27/08/07 18:16:

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:[email protected]>
 
D

David Thompson

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
 
D

David Thompson

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.h> and 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
 
D

David Thompson

:

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
 

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,755
Messages
2,569,536
Members
45,007
Latest member
obedient dusk

Latest Threads

Top