473,804 Members | 3,548 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Function prototypes

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
73 3471
Flash Gordon wrote:
>
Kenneth Brody wrote, On 27/08/07 18:16:
Keith Thompson wrote:
CBFalconer <cb********@yah oo.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
On Fri, 24 Aug 2007 08:22:22 -0400, Eric Sosman
<es*****@ieee-dot-org.invalidwrot e:
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.ne t
Sep 9 '07 #72
On Thu, 23 Aug 2007 20:04:25 -0400, pete <pf*****@mindsp ring.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.ne t
Sep 9 '07 #73
On Thu, 23 Aug 2007 14:28:14 -0700, "osmium" <r1********@com cast.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.ne t
Sep 9 '07 #74

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

21
3862
by: Rob Somers | last post by:
Hey people, I read a good thread on here regarding the reason why we use function prototypes, and it answered most of my questions, but I wanted to double check on a couple of things, as I am writing something up on functions, and I don't like writing about things I am not sure about. Ok, then, here we go: I initially thought that one would only really need to use a function
6
7996
by: Daniel Nichols | last post by:
I've noticed that in a C module (.c, .h file combination) that if you create a function's definition before it is used in other functions than a declaration is not necessary. I believe if the compiler can find the definition of the function prior to encountering the use of the function it will generate the prototype itself. I don't currently use this feature, I explicitly create declarations for all functions in a header file. However, I...
7
2380
by: junky_fellow | last post by:
Can a function have two different prototypes ? If not , then how can main() have two different prototypes ? int main(void) and int main argc(int argc, char *argv) I mean to say, if I declare main in either of the above mentioned ways my compiler does not give any warning. How can it accept two different prototypes ?
6
5013
by: Robbie Hatley | last post by:
I'm maintaining a software project with 134 C++ files, some of them huge (as much as 10,000 lines each), and very few prototypes. The author's attitude towards prototypes was like this: Prototypes are only good for headers to be included in other files. For functions which call each other inside one file, such as A calls B which calls C and D, just define the functions in order D, C, B, A, and you'll never need prototypes.
9
1665
by: wizwx | last post by:
what does the following mean? int func2(); According to C++, it surely means func2 is a function that takes no argument and returns an integer. But what about in C? Does it have the same meaning or does it mean that func2 is a function that takes any number of arguments and returns an integer? Thanks for any clarification.
1
5561
by: Noah Roberts | last post by:
Trying to use boost::function in a C++/CLI program. Here is code: pragma once #include <boost/function.hpp> #include <boost/shared_ptr.hpp> #include <vector> using namespace System;
16
7608
by: arne | last post by:
Hi all, imagine I call a function, but omit one of the parameters, like: foo.c: void foo( int a, int b ) { /* do something with a and b */ return; }
29
8089
by: Ravishankar S | last post by:
Dear C Experts, While prepating a content for a C course,I made section on function prototypes. Could you kindly provide me your comments on its correctness. Thank you ! Q12: What is the difference between a function prototype and a function declaration? If you get this right, you must have done fair amount of research on C
16
3291
by: Xiaoxiao | last post by:
Hi, I got a C library, is there a way to view the public function names in this library so that I can use in my C program? Thanks.
0
9706
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9579
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10326
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9143
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7615
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5520
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4295
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3815
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2990
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.