473,793 Members | 2,894 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 #1
73 3468
On Thu, 23 Aug 2007 01:12:41 +0200 (CEST), Steph Barklay
<do**@spam.mewr ote:
>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.
Is this for real? I find it hard to believe that any such teacher
exists. If this is not a troll, you should, if at all possible, enroll
in another class with a different teacher. If this is not possible,
ask your teacher to monitor this newsgroup for a while.

If that doesn't work, I don't know what to suggest. Probably you
should drop the course, and study C on your own.

--
Al Balmer
Sun City, AZ
Aug 22 '07 #2
On Aug 23, 11:40 am, Richard Heathfield <r...@see.sig.i nvalidwrote:
Your teacher is 100% wrong, brain-dead, and beyond redemption. Only
fools put code in headers.
Only fools and C++ programmers ;)

Aug 22 '07 #3
Steph Barklay <do**@spam.mewr ites:
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.
Your teacher is very very very very very wrong.

Ask him to explain section 4.5 of K&R2 (that's Kernighan & Ritchie,
_The C Programming Language_, 2nd Edition) (it starts on page 81),
which absolutely contradicts your teacher's claims.

--
Keith Thompson (The_Other_Keit h) 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 23 '07 #4
Old Wolf said:
On Aug 23, 11:40 am, Richard Heathfield <r...@see.sig.i nvalidwrote:
>Your teacher is 100% wrong, brain-dead, and beyond redemption. Only
fools put code in headers.

Only fools and C++ programmers ;)
But you repeat yourself. :-)

--
Richard Heathfield <http://www.cpax.org.uk >
Email: -www. +rjh@
Google users: <http://www.cpax.org.uk/prg/writings/googly.php>
"Usenet is a strange place" - dmr 29 July 1999
Aug 23 '07 #5
On Aug 22, 4:12 pm, Steph Barklay <d...@spam.mewr ote:
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.
Your teacher is criminally insane. Notify the authorities right away.

On the other hand, this is my evil handiwork:

#ifdef _MSC_VER
#include <windows.h>
#else
#include <unistd.h>
#endif

#include "searchr.c"
#include "search.c"
#include "thread.c"
#include "searchmp.c "
#include "repeat.c"
#include "next.c"
#include "nexte.c"
#include "nextr.c"
#include "history.c"
#include "quiesce.c"
#include "evaluate.c "
#include "movgen.c"
#include "make.c"
#include "unmake.c"
#include "hash.c"
#include "attacks.c"
#include "swap.c"
#include "boolean.c"
#include "utility.c"
#include "valid.c"
#include "probe.c"
#include "book.c"
#include "analyze.c"
#include "annotate.c "
#include "bench.c"
#include "data.c"
#ifndef _MSC_VER
#include "dgt.c"
#endif
#include "drawn.c"
#include "edit.c"
#include "epd.c"
#include "epdglue.c"
#include "evtest.c"
#include "init.c"
#include "input.c"
#include "interupt.c "
#include "iterate.c"
#include "learn.c"
#include "main.c"
#include "option.c"
#include "output.c"
#include "ponder.c"
#include "preeval.c"
#include "resign.c"
#include "root.c"
#include "setboard.c "
#include "test.c"
#include "time.c"
#include "validate.c "

On the other hand, each of those files has headers with prototypes and
there are headers with prototypes at the top even of this file.
Some compilers can inline more aggressively if you make every file
available as a single giant block of source code.
Aug 23 '07 #6
"Richard Heathfield" <rj*@see.sig.in validwrote in message
news:ct******** *************** *******@bt.com. ..
Your teacher is 100% wrong, brain-dead, and beyond redemption.
Only fools put code in headers.
99% wrong; there are valid reasons for code in headers, such as
function-like macros or static inline functions. However, I doubt that the
teacher was thinking about those things.

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 23 '07 #7
Steph Barklay wrote:
>
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.
Either the teacher, or your interpretation of his words, are
totally balmy.

--
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 23 '07 #8
Steph Barklay wrote:
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 misunderstandin g.

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.

--
Eric Sosman
es*****@ieee-dot-org.invalid
Aug 23 '07 #9
Steph Barklay wrote:
>
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.
That implies, or very nearly implies,
that professional programmers don't write C programs
with more than one file of source code.

It also suggests that your teacher has never
written a C program with more than one file of source code,
and thus is a neophyte programmer.
How old is this kid?

I hope that you're mistaken about what he said.
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
No.
or is my teacher wrong?
He absolutely does not understand what header files are for,
and is giving very strong indications
that he has no experience with multifile C programs.
Thank you.
Again, I very much hope that you have misunderstood what he meant.

--
pete
Aug 23 '07 #10

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

Similar topics

21
3860
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
7995
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
1664
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
7606
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
8088
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
3289
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
9518
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
10433
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10212
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
10000
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9035
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...
0
6777
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5436
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...
0
5560
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4112
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

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.