Function prototypes

P

pete

Kenneth said:
... nor use any standard library functions other than the non-varadic
ones that return int. (Bye bye malloc and printf, among others.)


Even neophytes can #include <stdio.h> on day one.

I was granting that he meant prototypes in source code.
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.
I think/hope "ditto" applies to everyone reading clc.

Me too.
(Though I
wouldn't hold my breath waiting for the answer to that.)

I think we would even prefer that Steph Barklay was trolling us
than that this could actually be happening.
But we all know that there's no limit to incompetence anywhere.
 
P

pete

osmium wrote:
Why burden the OP in this thread with a bunch of esoterica on the fine
points of the standard?
Presumably he wants to learn to write programs, not
how to write or interpret standards for a programming language.

OP already knows how to write programs.
OP wants to learn about data structures.
 
R

Richard Heathfield

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

If we assume he means "file scope objects", that's not an unreasonable
restriction. Even if, later on, you become a wild, unmanageable
programmer who splashes objects all over memory, you ought at least to
know /how/ to use parameters.
2. All variables must be in lower case, with clear and concise names
that depict what data the varible will contain.

Presumably he means object names. Again, not unreasonable, although
personally I prefer camel case.
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).
4. Use of global constants, such as PI, is permitted

How kind. :)
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.

As has already been pointed out by myself and others elsethread, this
makes C programming impossible; realistically, it actually means that
the teacher doesn't know what a prototype is, and it effectively
restricts each solution to a single source file.

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?

<snip>
 
R

Richard Heathfield

Default User said:
I don't agree. I believe the rule indicates that no prototype
declarations are to be used.

So, this:


void f(void)

That's a "prototype declaration" - i.e. a declaration that is also a
prototype. (That's not all it is, either.)
{
}

int main(void)

Same applies here.
 
E

Eric Sosman

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

I blam our flawhed eductaional sistym!
 
O

Old Wolf

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

Maybe the "principle programmer" is the programmer who's
responsible for following design principles?
 
C

CBFalconer

Old said:
Maybe the "principle programmer" is the programmer who's
responsible for following design principles?

My principal programming pal takes deep umbrage at this frolicsome
debauchery of the principles of English spelling.
 
R

Ravishankar S

No, probably slower -- a lot slower.
The above technique does not speed up compilation (generally compiles
run much slower). On some systems, it will increase the executable
speed of the binary.

No, what I mean is have a seperate source files , but a single header
declaring all that is required. saving preprocrocessing time...
 
R

Richard Bos

kuyper said:
I strongly suspect that in this context, your teacher is misusing the
word prototype. I suspect that he is not prohibiting the use of
prototypes that enter your code through standard headers, and he is
not prohibiting the use of prototypes at the start of a function
definition. I suspect that the only thing he intends to prohibit is
prototypes for your own functions, which are not part of the function
definition.

I suspect that the only thing he intends to prohibit is _separate_
prototypes for your own functions, but either does not know the subject
he's teaching enough to know the difference, or does not care enough to
be precise. In both cases, given that this is a programming course (and
not one in, say, sociology, where imprecision is an advantage), my
advice would still be: run, do not walk, _run_, away from this course.

Richard
 
A

Army1987

On Thu, 23 Aug 2007 22:49:04 +0200, Steph Barklay wrote:
[top-post fixed]
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.
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."
Most standard headers are *very* unlikely to conform to them.
And what is a global constant? An identifier with file scope for
an object declared as const, or a preprocessor macro? If you
aren't a troll, your teacher is either confused or trying to
confuse you.
 
R

Richard Tobin

Army1987 said:
#include <stdio.h>
#include <ctype.h>

I'm not sure that this is allowed, since those header files probably
contain prototypes, and header files were supposed to conform to the
same rules.

-- Richard
 
A

Army1987

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++));
printf("\"PROGRAM\"");
while (*s2) putchar(tolower(*s2++));
puts("");
return 0;
}
 
R

Richard Heathfield

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! :)
 
E

Eric Sosman

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

CBFalconer

Eric said:
Army1987 said:
Richard 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. Suggested fix:

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

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

Peter J. Holzer

No, what I mean is have a seperate source files , but a single header
declaring all that is required. saving preprocrocessing time...

That depends. It will probably speed up compiling if you compile
everything from scratch. But if you have a build system which
recompiles only those source files which changed or which include a
changed file, you will have to recompile everything a lot more often if
you only have one header file than if you have a lot of little header
files.

(Poor organization may have a similar impact. For example the Minix OS
of course had a lot of include files, but almost all OS parameters were
defined in a single central include file, which was of course included
in almost all system source files. So, if you changed any of these
parameters (which was probably used in a handful of places) you had to
recompile almost everything)

hp
 
C

Charlton Wilbur

o> Your instructor is pathetic. He is talking about little toy
o> programs, the kind you write in the very class you are enrolled
o> in. My guess is that he has never seen the code for a real
o> program in his entire life.

Er, based on subsequent statements, and in an attempt to be
charitable, I don't think the instructor was really claiming that
nobody ever uses prototypes. He's teaching a data structures class,
and 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.
Allowing multiple files means that he's suddenly got to deal with
multiple files per student and differing build procedures, and he's
probably not interested in teaching a class in Makefiles and tar -cf,
or worse, the IDE du jour; and if this is a data structures class,
it's probably aimed at first- or second-year students, who are in the
process of learning to walk before they run.

On the other hand, had he specified what he wanted, instead of using
silly technical restrictions that he thought he would get what he
wanted, he'd be more likely to get what he wanted, and he'd seem like
less of an idiot. This is a valuable lesson for any programmer or
project manager.

Charlton
 
D

Default User

Richard said:
Default User said:

That's a "prototype declaration" - i.e. a declaration that is also a
prototype. (That's not all it is, either.)

Of course. However, most situations are NOT comp.lang.c. Even when I
was working on large C projects, prototype declarations were commonly
just clled "prototypes". K&R style wasn't allowed to be used period, so
there was no ambiguity.

When comes down to interpreting an instructor's directions, I think it
highly unlikely that he or she is requiring old-style functions, but
rather is talking about not using separate declaration of functions.

Yes it's a bit of loose terminology, but I really don't think strange
tangential speculation helps this poor guy out.




Brian
 

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

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,057
Latest member
KetoBeezACVGummies

Latest Threads

Top