|
Next: quicktime broadcaster communication with quicktim..
|
| Author |
Message |
External

Since: Oct 14, 2005 Posts: 2
|
(Msg. 1) Posted: Fri Oct 14, 2005 9:51 pm
Post subject: No return statement does NOT result in a compile error!!! Archived from groups: comp>sys>mac>programmer>help (more info?)
|
|
|
Hello,
I have 1 question. If I create a XCode default C++ Command Line application
and change the default main.cpp (remove the return statement) to:
int main(int argc,char** arg) {
}
I do NOT get a compile time error on the missing return statement. Which
compiler option do I need to enable to let the compiler check on this kind
of mistakes. ( I assume a GCC option?) ? Where do I set this option in
XCode?
Thanks!
Jos |
|
| Back to top |
|
 |  |
External

Since: Aug 26, 2005 Posts: 38
|
(Msg. 2) Posted: Fri Oct 14, 2005 9:51 pm
Post subject: Re: No return statement does NOT result in a compile error!!! [Login to view extended thread Info.] Archived from groups: per prev. post (more info?)
|
|
|
In article <dip281$3gu$1@news3.zwoll1.ov.home.nl>, "Jos" <nospam.DeleteThis@nospam.com>
wrote:
> I have 1 question. If I create a XCode default C++ Command Line application
> and change the default main.cpp (remove the return statement) to:
>
> int main(int argc,char** arg) {
> }
>
> I do NOT get a compile time error on the missing return statement. Which
> compiler option do I need to enable to let the compiler check on this kind
> of mistakes. ( I assume a GCC option?) ? Where do I set this option in
> XCode?
The C++ standard specifies that a main() with no return statement implicitly
returns 0. I am not aware of an option that produces a warning in this case.
(Xcode does warn by default about missing return statements in other functions.)
hth
Ben
--
If this message helped you, consider buying an item
from my wish list: <http://artins.org/ben/wishlist>
I changed my name: <http://periodic-kingdom.org/People/NameChange.php> |
|
| Back to top |
|
 |  |
External

Since: Oct 22, 2005 Posts: 23
|
(Msg. 3) Posted: Sat Oct 15, 2005 12:21 am
Post subject: Re: No return statement does NOT result in a compile error!!! [Login to view extended thread Info.] Archived from groups: per prev. post (more info?)
|
|
|
Jos wrote:
> I have 1 question. If I create a XCode default C++ Command Line application
> and change the default main.cpp (remove the return statement) to:
>
> int main(int argc,char** arg) {
> }
>
> I do NOT get a compile time error on the missing return statement.
somebody else pointed out that main() is a special case. however, even in
regular functions, gcc by default does not give me errors or warnings for
missing return statements. i'm still using macosx 10.3.9 though, so that may
be part of it. what i did was add some text to the "other warning flags"
field of my projects' build styles, like this:
-Wreturn-type
that fixed it. it really should be turned on be default, though. lord only
knows why it isn't. |
|
| Back to top |
|
 |  |
External

Since: Jun 24, 2005 Posts: 9
|
(Msg. 4) Posted: Sat Oct 15, 2005 12:21 am
Post subject: Re: No return statement does NOT result in a compile error!!! [Login to view extended thread Info.] Archived from groups: per prev. post (more info?)
|
|
|
Allen Brunson <brunsona DeleteThis @takethisout.newsguy.com> writes:
> what i did was add some text to the "other warning flags"
> field of my projects' build styles, like this:
>
> -Wreturn-type
Even better:
-Wall
sherm--
--
Cocoa programming in Perl: http://camelbones.sourceforge.net
Hire me! My resume: http://www.dot-app.org |
|
| Back to top |
|
 |  |
External

Since: Mar 21, 2006 Posts: 164
|
(Msg. 5) Posted: Sat Oct 15, 2005 5:01 am
Post subject: Re: No return statement does NOT result in a compile error!!! [Login to view extended thread Info.] Archived from groups: per prev. post (more info?)
|
|
|
Sherm Pendley <sherm RemoveThis @dot-app.org> wrote:
> Allen Brunson <brunsona RemoveThis @takethisout.newsguy.com> writes:
>
>> what i did was add some text to the "other warning flags"
>> field of my projects' build styles, like this:
>>
>> -Wreturn-type
>
> Even better:
>
> -Wall
Better yet (IMO):
-W -Wall -Wno-unused-parameter
This turns on insane levels of warnings, and then disables
unused-parameter warnings because Cocoa really encourages them, so they
tend to get deeply annoying. Other than some altivec initializers, these
warnings have saved my goose more than once, and never been a major
hassle.
--
Michael Ash
Rogue Amoeba Software |
|
| Back to top |
|
 |  |
External

Since: Jun 06, 2005 Posts: 660
|
(Msg. 6) Posted: Sat Oct 15, 2005 9:17 am
Post subject: Re: No return statement does NOT result in a compile error!!! [Login to view extended thread Info.] Archived from groups: per prev. post (more info?)
|
|
|
In article <1129370497.774641.DeleteThis@nfs-db1.segnet.com>,
Michael Ash <mike.DeleteThis@mikeash.com> wrote:
> Sherm Pendley <sherm.DeleteThis@dot-app.org> wrote:
> > Allen Brunson <brunsona.DeleteThis@takethisout.newsguy.com> writes:
> >
> >> what i did was add some text to the "other warning flags"
> >> field of my projects' build styles, like this:
> >>
> >> -Wreturn-type
> >
> > Even better:
> >
> > -Wall
>
> Better yet (IMO):
>
> -W -Wall -Wno-unused-parameter
>
> This turns on insane levels of warnings, and then disables
> unused-parameter warnings because Cocoa really encourages them, so they
> tend to get deeply annoying. Other than some altivec initializers, these
> warnings have saved my goose more than once, and never been a major
> hassle.
You can avoid the unused parameter warnings also by putting
#pragma unused (parameter_name)
in the function body. It's not universal (although it is widespread) but
it shouldn't break any conformat compiler and provides an additional
level of documentation.
--
Goal 2005: Convincing James Hetfield to cover the Strawberry Shortcake
"Are You Berry Berry Happy?" song. |
|
| Back to top |
|
 |  |
External

Since: Oct 15, 2005 Posts: 2
|
(Msg. 7) Posted: Sat Oct 15, 2005 2:03 pm
Post subject: Re: No return statement does NOT result in a compile error!!! [Login to view extended thread Info.] Archived from groups: per prev. post (more info?)
|
|
|
Michael Ash <mike.RemoveThis@mikeash.com> wrote:
> Sherm Pendley <sherm.RemoveThis@dot-app.org> wrote:
> > Allen Brunson <brunsona.RemoveThis@takethisout.newsguy.com> writes:
> >
> >> what i did was add some text to the "other warning flags"
> >> field of my projects' build styles, like this:
> >>
> >> -Wreturn-type
> >
> > Even better:
> >
> > -Wall
>
> Better yet (IMO):
>
> -W -Wall -Wno-unused-parameter
>
> This turns on insane levels of warnings, and then disables
> unused-parameter warnings because Cocoa really encourages them, so they
> tend to get deeply annoying. Other than some altivec initializers, these
> warnings have saved my goose more than once, and never been a major
> hassle.
And for gcc4.0 I think it's
-Wextra -Wall -Wno-unused-parameter
--
Frédéric Testuz
<mailto:ftestuz@SANSPUBmac.com.invalid> |
|
| Back to top |
|
 |  |
External

Since: Jun 24, 2005 Posts: 9
|
(Msg. 8) Posted: Sat Oct 15, 2005 3:35 pm
Post subject: Re: No return statement does NOT result in a compile error!!! [Login to view extended thread Info.] Archived from groups: per prev. post (more info?)
|
|
|
Gregory Weston <uce RemoveThis @splook.com> writes:
> You can avoid the unused parameter warnings also by putting
> #pragma unused (parameter_name)
> in the function body.
Thanks for the tip - I'm much more comfortable with flagging specific cases
than with disabling the warning globally.
sherm--
--
Cocoa programming in Perl: http://camelbones.sourceforge.net
Hire me! My resume: http://www.dot-app.org |
|
| Back to top |
|
 |  |
External

Since: Sep 19, 2005 Posts: 43
|
(Msg. 9) Posted: Sat Oct 15, 2005 3:44 pm
Post subject: Re: No return statement does NOT result in a compile error!!! [Login to view extended thread Info.] Archived from groups: per prev. post (more info?)
|
|
|
In article <uce-53BC31.09172015102005 RemoveThis @comcast.dca.giganews.com>,
Gregory Weston <uce RemoveThis @splook.com> wrote:
> In article <1129370497.774641 RemoveThis @nfs-db1.segnet.com>,
> Michael Ash <mike RemoveThis @mikeash.com> wrote:
>
> > Better yet (IMO):
> >
> > -W -Wall -Wno-unused-parameter
> >
> > This turns on insane levels of warnings, and then disables
> > unused-parameter warnings because Cocoa really encourages them, so they
> > tend to get deeply annoying.
>
> You can avoid the unused parameter warnings also by putting
> #pragma unused (parameter_name)
> in the function body. It's not universal (although it is widespread) but
> it shouldn't break any conformat compiler and provides an additional
> level of documentation.
Another way to do that is by commenting or leaving out the variable name
in the implementation:
void aFunction( int x, char * /* anAnusedVariable */)
{
...
}
I haven't seen a compiler that does not understand this.
Reinder |
|
| Back to top |
|
 |  |
External

Since: Aug 26, 2005 Posts: 38
|
(Msg. 10) Posted: Sat Oct 15, 2005 3:44 pm
Post subject: Re: No return statement does NOT result in a compile error!!! [Login to view extended thread Info.] Archived from groups: per prev. post (more info?)
|
|
|
In article <reinder-210D5C.15442815102005.DeleteThis@reader28.wxs.nl>,
Reinder Verlinde <reinder.DeleteThis@verlinde.invalid> wrote:
> Another way to do that is by commenting or leaving out the variable name
> in the implementation:
>
> void aFunction( int x, char * /* anAnusedVariable */)
> {
> ...
> }
>
> I haven't seen a compiler that does not understand this.
I believe this is legal in C++ but not in C; don't know about Obj-C/C++
Ben
--
If this message helped you, consider buying an item
from my wish list: <http://artins.org/ben/wishlist>
I changed my name: <http://periodic-kingdom.org/People/NameChange.php> |
|
| Back to top |
|
 |  |
External

Since: Jun 07, 2005 Posts: 5
|
(Msg. 11) Posted: Sat Oct 15, 2005 3:44 pm
Post subject: Re: No return statement does NOT result in a compile error!!! [Login to view extended thread Info.] Archived from groups: per prev. post (more info?)
|
|
|
in article reinder-210D5C.15442815102005.RemoveThis@reader28.wxs.nl, Reinder Verlinde
at reinder.RemoveThis@verlinde.invalid wrote on 10/15/05 6:44 AM:
> Another way to do that is by commenting or leaving out the variable name
> in the implementation:
>
> void aFunction( int x, char * /* anAnusedVariable */)
> {
> ...
> }
>
> I haven't seen a compiler that does not understand this.
Oddly enough, I just ran into one two days ago that can't handle exactly
that, when an I-thought-innocent checkin broke the other guys' compile, and
much angst ensued. You might have heard of their compiler, too, even if you
haven't seen it; it's called "Visual C++" and it's from a company called
"Microsoft".
.... only in .c files, mind you. But still. |
|
| Back to top |
|
 |  |
External

Since: Sep 19, 2005 Posts: 43
|
(Msg. 12) Posted: Sat Oct 15, 2005 11:56 pm
Post subject: Re: No return statement does NOT result in a compile error!!! [Login to view extended thread Info.] Archived from groups: per prev. post (more info?)
|
|
|
In article <BF76BAE2.19457%alex@alexcurylo.com>,
Alex Curylo <alex RemoveThis @alexcurylo.com> wrote:
> in article reinder-210D5C.15442815102005 RemoveThis @reader28.wxs.nl, Reinder Verlinde
> at reinder RemoveThis @verlinde.invalid wrote on 10/15/05 6:44 AM:
>
> > Another way to do that is by commenting or leaving out the variable name
> > in the implementation:
> >
> > void aFunction( int x, char * /* anAnusedVariable */)
> > {
> > ...
> > }
> >
> > I haven't seen a compiler that does not understand this.
>
> Oddly enough, I just ran into one two days ago that can't handle exactly
> that, when an I-thought-innocent checkin broke the other guys' compile, and
> much angst ensued. You might have heard of their compiler, too, even if you
> haven't seen it; it's called "Visual C++" and it's from a company called
> "Microsoft".
>
> ... only in .c files, mind you. But still.
Well, you are never old enough to learn. Apparently, I have seen a
compiler tat does not understand that, but I haven't looked close enough
at it.
In article <macdev-AF4269.13280015102005 RemoveThis @pbdl.news.astraweb.com>, Ben
Artin <macdev RemoveThis @artins.org> wrote:
> I believe this is legal in C++ but not in C; don't know about Obj-C/C++
My guesstimate would be that it will be OK in Obj-C++, but not in Obj-C,
since, for all x, Obj-x is just x with a few additions.
Reinder |
|
| Back to top |
|
 |  |
External

Since: Oct 21, 2005 Posts: 1
|
(Msg. 13) Posted: Fri Oct 21, 2005 7:03 pm
Post subject: Re: No return statement does NOT result in a compile error!!! [Login to view extended thread Info.] Archived from groups: per prev. post (more info?)
|
|
|
Hi,
Gregory Weston writes:
> You can avoid the unused parameter warnings also by putting
> #pragma unused (parameter_name)
> in the function body. It's not universal (although it is widespread) but
I use
(void) parameter_name;
Although I have seen compilers that give a (different) warning about
this, it's not quite as compiler specific as a #pragma.
benny |
|
| Back to top |
|
 |  |
| Related Topics: | Source file Compile (Cmd-K) option is greyed out? - Hi, Every so often (usually in downloaded example code) I have a source file (.mm or .cpp) that won't compile, forcing me to do a full build to check it. I had this problem a while back and the solution was to upgrade the target to native, but I've done...
6 DAY compile! Any volunteers for distributed build CPU sh.. - Hello! I have a simple, but very large, unix command line C program that I am compiling. It consists of about 1000 separate source files, the largest of which is 20 MB, the smallest about 16 KB (source code). I have just completed the initial..
Template Syntax Error in Xcode: parse error before `>' token - I'm porting some code over from Codewarrior and have run into a problem with method templates. I have a class with a template method, which passes the typename to another template method of another class object. So in the code below, the mBuffer object..
error: parse error before "}" token (newbie needs help) - Hello First post on this board with a question relating to my first venture into xcode, I have a little bit of programming experience on the windows side, im new to macs as well so please go easy on me.. I have system 10.3.9 and am using xcode version....
What causes the 'can't map file' error? - I'm porting open source for Linux to Mac OS X. I think I generated every .a or .lib but the final link gives an error message. /usr/bin/ld: can't map file: /Users/smcho/Desktop/OpenAccess/lib/mac_osx_32/opt ((os/kern) invalid argument) What might be.. |
|
You can post new topics in this forum You can reply to topics in this forum You can edit your posts in this forum You can delete your posts in this forum You can vote in polls in this forum
|
|
|
|