473,413 Members | 1,807 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,413 software developers and data experts.

default int

I've been told that c99 forbids declarations of functions without return
type and defaulting them to return int. So why compiling the following
code with 'gcc a.c -Wall -std=c99' only gives a few warnings?

--
Devaraja (Xdevaraja87^gmail^c0mX)
Linux Registerd User #338167
http://counter.li.org
Nov 15 '05 #1
6 3032
DevarajA wrote:
I've been told that c99 forbids declarations of functions without return
type and defaulting them to return int.
Implicit int is gone from the language with C99, yes.

So why compiling the following
code with 'gcc a.c -Wall -std=c99' only gives a few warnings?


What code?

If you want to know how to invoke your compiler in C99 mode, I suggest
"man gcc" and -- if that does not help you -- gnu.gcc.help; it is
off-topic round here.

<OT>
The short of it:
gcc -std=c99 -pedantic
will do. If you want to have some more useful warnings, I suggest -O
along with -Wall.
However, gcc is not fully C99 compliant. See
<http://gcc.gnu.org/c99status.html>
for more information. There are other issues on certain target
platforms.
</OT>
Cheers
Michael
--
E-Mail: Mine is an /at/ gmx /dot/ de address.
Nov 15 '05 #2
Michael Mair ha scritto:
DevarajA wrote:
I've been told that c99 forbids declarations of functions without
return type and defaulting them to return int.

Implicit int is gone from the language with C99, yes.

So why compiling the following code with 'gcc a.c -Wall -std=c99' only
gives a few warnings?

What code?


Sorry, forgot it :-)
--
main(){}
--
Anyway thank you for the info.
--
Devaraja (Xdevaraja87^gmail^c0mX)
Linux Registerd User #338167
http://counter.li.org
Nov 15 '05 #3
DevarajA wrote:
I've been told that c99 forbids declarations of functions without return
type and defaulting them to return int.
Previous versions of C allowed you to leave out the return type of a
function. If you did so, it would assume that you meant to make the
function return int. This feature was called "implicit int", not
"default int".

C99 removed the "implicit int" feature, making it a "constraint
violation" to leave out the return type when declaring or defining a
function. As you should know, constraint violations must be detected by
the compiler, and at least one "diagnostic message" must be output. A
constraint violation does not mean that the compiler must refuse to
translate the program.

The C standard does not talk of "warnings" or "errors", but only of
"diagnostics". Both warnings and errors are types of diagnostics. If you
get a warning from your compiler, that is your diagnostic. A warning IS
a diagnostic message just as much as an error is. It's just that the
compiler writers decided that they could continue translation in that case.
So why compiling the following
code with 'gcc a.c -Wall -std=c99' only gives a few warnings?


You left out the code and the warnings, but I can imagine it says
something similar to this:

[sbiber@eagle c]$ cat a.c
main(){}
[sbiber@eagle c]$ gcc a.c -Wall -std=c99
a.c:1: warning: return type defaults to `int'

This compiler is behaving correctly. It diagnosed the constraint
violation by outputting a warning. End of story.

--
Simon.
Nov 15 '05 #4
DevarajA <no@spam.com> writes:
Michael Mair ha scritto:
DevarajA wrote:
I've been told that c99 forbids declarations of functions without
return type and defaulting them to return int.

Implicit int is gone from the language with C99, yes.

So why compiling the following code with 'gcc a.c -Wall -std=c99' only
gives a few warnings?

What code?


Sorry, forgot it :-)
--
main(){}
--
Anyway thank you for the info.


You should show us what warnings you got in addition to the code. Not
everyone has gcc; not everyone who has gcc has the same version you
have.

Here's what I get:

% gcc a.c -Wall -std=c99
a.c:1: warning: return type defaults to `int'

The standard requires a diagnostic. It doesn't require the compiler
to reject the program. It doesn't even require the diagnostic to be
meaningful. gcc's behavior is conforming.

--
Keith Thompson (The_Other_Keith) 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.
Nov 15 '05 #5
Keith Thompson ha scritto:
DevarajA <no@spam.com> writes:
Michael Mair ha scritto:
DevarajA wrote:
I've been told that c99 forbids declarations of functions without
return type and defaulting them to return int.
Implicit int is gone from the language with C99, yes.

So why compiling the following code with 'gcc a.c -Wall -std=c99' only
gives a few warnings?
What code?


Sorry, forgot it :-)
--
main(){}
--
Anyway thank you for the info.

You should show us what warnings you got in addition to the code. Not
everyone has gcc; not everyone who has gcc has the same version you
have.

Here's what I get:

% gcc a.c -Wall -std=c99
a.c:1: warning: return type defaults to `int'


This is exactly the warning I get.

--
Devaraja (Xdevaraja87^gmail^c0mX)
Linux Registerd User #338167
http://counter.li.org
Nov 15 '05 #6
DevarajA wrote:
[...]
>I've been told that c99 forbids declarations of functions without
>return type and defaulting them to return int. [...]>So why compiling the following code with 'gcc a.c -Wall -std=c99' only
>gives a few warnings? [...]main(){}
[...] Here's what I get:

% gcc a.c -Wall -std=c99
a.c:1: warning: return type defaults to `int'


This is exactly the warning I get.


So what's the problem? You didn't specify "int" as the return type,
and it gave a warning about it, as you expected. What other warnings
did you expect, and why? (How many errors/warning should a program of
9 characters [including the newline] with no syntax errors generate?)

--
+-------------------------+--------------------+-----------------------------+
| Kenneth J. Brody | www.hvcomputer.com | |
| kenbrody/at\spamcop.net | www.fptech.com | #include <std_disclaimer.h> |
+-------------------------+--------------------+-----------------------------+
Don't e-mail me at: <mailto:Th*************@gmail.com>
Nov 15 '05 #7

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

Similar topics

12
by: earl | last post by:
class temp { public: temp(); foo(char, char, char*); private: char matrix; }; temp::foo(char p, char o, char m = matrix )
0
by: inquirydog | last post by:
Hi- I am using xml to hold configuration data for a project, and using schema to define what the configuration file should look like. I wanted to get some advice on an intelligant way to...
15
by: A | last post by:
Hi, A default copy constructor is created for you when you don't specify one yourself. In such case, the default copy constructor will simply do a bitwise copy for primitives (including...
4
by: Steven T. Hatton | last post by:
I mistakenly set this to the comp.std.c++ a few days back. I don't believe it passed the moderator's veto - and I did not expect or desire anything different. But the question remains: ISO/IEC...
10
by: Ook | last post by:
I'm having trouble comprehending what exactly "default construction" is. I know how to provide a constructor with initial values, so that if I, for example, in my code do this: MyClass...
19
by: Andrew J. Marshall | last post by:
I want to create a class that must receive a parameter when instantiated. In other words, I do not want it to have a "Public Sub New()". 1) Does VB.NET create a default public constructor if I do...
74
by: Zytan | last post by:
I have a struct constructor to initialize all of my private (or public readonly) fields. There still exists the default constructor that sets them all to zero. Is there a way to remove the...
4
by: Jess | last post by:
Hello, I tried several books to find out the details of object initialization. Unfortunately, I'm still confused by two specific concepts, namely default-initialization and...
4
by: Macneed | last post by:
i am a newbie, i remember i read a book talking about when u declare a array variable using float ABC = new float; the whole array element in ABC ( ABC to ABC ) will automatic initialize to 0...
7
by: =?Utf-8?B?Y291Z2FyaXN0aWM=?= | last post by:
I am trying to convert an C# application to VB and have one issue which is converting the generic value to the default. C# uses return default(T) as the return value how would I translate this in...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
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...
0
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,...
0
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...
0
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...
0
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,...
0
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...
0
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...

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.