Hi,
do I have to provide the return type when a function
is declared in ANSI C-99?
Or would
main ( void ) { ... }
be enough?
Gcc does not complain and I could not find any
corresponding paragraphs in the standard ISO/IEC 9899:1999.
Regards,
Christian 9 2441
Christian Christmann wrote: Hi,
do I have to provide the return type when a function is declared in ANSI C-99?
tom@bigbox ~ $ cat test.c
test(void) { 1; }
tom@bigbox ~ $ gcc --std=c99 -pedantic -Wall -W -O3 -c test.c
test.c:1: warning: return type defaults to 'int'
test.c: In function 'test':
test.c:1: warning: statement with no effect
test.c:1: warning: control reaches end of non-void function
You were saying about not getting warnings?
Do yourself a favour, put return types on all of your functions.
Tom
Christian Christmann wrote: Hi,
do I have to provide the return type when a function is declared in ANSI C-99?
Or would
main ( void ) { ... }
be enough?
Gcc does not complain and I could not find any corresponding paragraphs in the standard ISO/IEC 9899:1999.
I think that this "feature" is "deprecated " in C99. Even if it wasn't
it's always been a good idea to spell out what you mean.
Christian Christmann wrote: Hi,
do I have to provide the return type when a function is declared in ANSI C-99?
Or would
main ( void ) { ... }
be enough?
Gcc does not complain and I could not find any corresponding paragraphs in the standard ISO/IEC 9899:1999.
Regards, Christian
I think it's os and compiler dependant on what the entry point's type
and parameter set should be, but to be on the safe side, I always go with:
int main( int argc, char ** argv )
Inmatarian.
Christian Christmann wrote: Hi,
do I have to provide the return type when a function is declared in ANSI C-99?
Yes.
C89 defines: main(){return 0;}
C99 defines: int main(){}
Both versions of the language say
that empty parameter lists are obsolescent.
Best is: int main(void){retu rn 0;}
--
pete
Christian Christmann said: Hi,
do I have to provide the return type when a function is declared in ANSI C-99?
Yes.
Or would
main ( void ) { ... }
be enough?
No. C99 removes implicit int from the language.
Gcc does not complain and I could not find any corresponding paragraphs in the standard ISO/IEC 9899:1999.
gcc is not C99-conforming.
The reason you can't find anything about implicit int in the Standard is
that you're looking for something that isn't there. The closest you'll get
to finding it is the text "remove implicit int" in the list of changes.
--
Richard Heathfield
"Usenet is a strange place" - dmr 29/7/1999 http://www.cpax.org.uk
email: rjh at above domain (but drop the www, obviously)
On Tue, 27 Jun 2006 15:35:59 +0200, Christian Christmann
<pl*****@yahoo. de> wrote in comp.lang.c: Hi,
do I have to provide the return type when a function is declared in ANSI C-99?
Or would
main ( void ) { ... }
be enough?
Gcc does not complain and I could not find any corresponding paragraphs in the standard ISO/IEC 9899:1999.
Actually, although some of the others could not find it, it is
specifically spelled out in C99.
The first sentence of paragraph 2 of 6.7.2 Type specifiers states
this, in a constraints clause:
"At least one type specifier shall be given in the declaration
specifiers in each declaration, and in the specifier-qualifier list in
each struct declaration and type name."
This sentence explicitly removes "implicit int" from C.
Since the definition of a function or object is also a declaration, it
is subject to the same constraints. A constraint violation requires a
diagnostic.
Perhaps you are not invoking your version of gcc in C99 conforming
mode, or that is one of the C99 features not in your version.
--
Jack Klein
Home: http://JK-Technology.Com
FAQs for
comp.lang.c http://c-faq.com/
comp.lang.c++ http://www.parashift.com/c++-faq-lite/
alt.comp.lang.l earn.c-c++ http://www.contrib.andrew.cmu.edu/~a...FAQ-acllc.html
Richard Heathfield <in*****@invali d.invalid> writes: Christian Christmann said:
[...] Gcc does not complain and I could not find any corresponding paragraphs in the standard ISO/IEC 9899:1999.
gcc is not C99-conforming.
True, but it does conform to this particular C99 requirement when
invoked with the proper command-line options.
--
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.
inmatarian <wc*****@gmail. com> writes: Christian Christmann wrote: Hi, do I have to provide the return type when a function is declared in ANSI C-99? Or would main ( void ) { ... } be enough? Gcc does not complain and I could not find any corresponding paragraphs in the standard ISO/IEC 9899:1999. Regards, Christian
I think it's os and compiler dependant on what the entry point's type and parameter set should be, but to be on the safe side, I always go with:
int main( int argc, char ** argv )
Any conforming hosted implementation must accept
int main(int argc, char *argv[])
or
int main(void)
or equivalent (your declaration qualifies). Implementations may
define other forms, but there's hardly ever any good reason to use
them.
In a freestanding implementation, the entry point is
implementation-defined; the implementation needn't support "main" at
all. (A freestanding implementation needn't support most of the
standard library either.)
--
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.
Keith Thompson said: Richard Heathfield <in*****@invali d.invalid> writes: Christian Christmann said: [...] Gcc does not complain and I could not find any corresponding paragraphs in the standard ISO/IEC 9899:1999.
gcc is not C99-conforming.
True, but it does conform to this particular C99 requirement when invoked with the proper command-line options.
The later versions, maybe. (The version I have here doesn't, because it's
slightly older than dmr, but of course that's my problem. Nevertheless,
those whose code has to compile under earlier versions of gcc need to be
aware of this.)
--
Richard Heathfield
"Usenet is a strange place" - dmr 29/7/1999 http://www.cpax.org.uk
email: rjh at above domain (but drop the www, obviously) This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Brad Tilley |
last post by:
Is there an easier way to do this:
def print_whats_returned(function):
print function
print type(function)
|
by: Derek Hart |
last post by:
I wish to execute code from a string. The string will have a function name,
which will return a string:
Dim a as string
a = "MyFunctionName(param1, param2)"
I have seen a ton of people discuss how reflection does this, but I cannot
find the syntax to do this. I have tried several code example off of
gotdotnet and other articles. Can somebody please show me the code to do
this?
|
by: marcelf3 |
last post by:
Hello..
This page opens a window with some information, but everytime the user
changes a field in the parent window, the child window needs to be
closed.
These 2 functions were supposed to do the work.
Nota() - opens new window.
fechaNota() - closes the window opened by Nota()
here is the code.
|
by: Edward Diener |
last post by:
In C++ an overridden virtual function in a derived class must have the exact
same signature of the function which is overridden in the base class, except
for the return type which may return a pointer or reference to a derived
type of the base class's return type.
In .NET the overridden virtual function is similar, but an actual parameter
of the function can be a derived reference from the base class's reference
also.
This dichotomy...
|
by: cmk128 |
last post by:
Hi
Why put * in front of the function name in the declaration?
int (*write)(struct inode *, struct file *, const char *, int);
thanks
from Peter (cmk128@hotmail.com)
| |
by: Ian Bicking |
last post by:
I got a puzzler for y'all. I want to allow the editing of functions
in-place. I won't go into the reason (it's for HTConsole --
http://blog.ianbicking.org/introducing-htconsole.html), except that I
really want to edit it all in-process and in-memory. So I want the
identity of the function to remain the same, even as I edit the body
and hopefully the signature too.
Well, the reason is that I want to edit any function object, without...
|
by: ben.carbery |
last post by:
Hi,
I have just written a simple program to get me started in C that
calculates the number of days since your birthdate.
One thing that confuses me about the program (even though it works) is
how global variables and function returns work...
For example, I have a global array "char datestring;" which is
defined in the function speakdate. speakdate just converts a set of
integers (date variables) to a string.
|
by: I.M. !Knuth |
last post by:
Hi. I'm more-or-less a C newbie. I thought I had pointers under control until
I started goofing around with this:
================================================================================
/* A function that returns a pointer-of-arrays to the calling function. */
#include <stdio.h>
int *pfunc(void);
|
by: Christian Christmann |
last post by:
Hi,
in a benchmark I've found an uncommon use of a function.
This is the simplified form:
1 int foo( int f )
2 {
3 return f;
4 }
5
|
by: simon |
last post by:
hi,
I would like to separate my javascript completely from my xhtml. in the
end there should be only
<script type="text/javascript" src="javalib.js"></script>
in the head-tag to my javascript.
Because I want to use some ajax-requests and other javascript-functions
on my xhtml, I need to dynamically add event handlers to any possible
dom-elements. All solutions I found so fare are for specific, pre-known
|
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...
| |
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,...
|
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...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
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...
|
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();...
|
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: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
|
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...
| |