Sigh. It's been awhile since I've programmed in C, but I'm SURE that
you can have a function whose scope is purely within another function.
Yet here I have a program which compiles without a peep under gcc4.2.1
(with -ansi -Wall, no less), AND runs correctly, but which icc
(10.1.015) won't touch with a ten-foot-pole:
=====begin sample program=====
#include <stdio.h>
int main()
{
int sub1()
{
printf("1");
return(0);
}
int sub2()
{
printf("2\n");
return(0);
}
/* start of main */
sub1();
sub2();
}
=======end sample program========
I don't see anything wrong with this. Nevertheless, icc aborts the
compilation with the fatal error
testit.c(6): error: expected a ";"
{
^
It doesn't like the opening left-brace of "sub1".
Now, I've read this group before, and I know I'm going to get reamed
for such a simple question, but: what's wrong? And why does one
compiler pass it and the other doesn't?
This is in openSuse 10.3 on a 2.5GHz core 2 duo with 3GB RAM (though
none of that matters).
Thanks in advance,
--
Ron Bruck 17 3356
Ronald Bruck wrote:
Sigh. It's been awhile since I've programmed in C, but I'm SURE that
you can have a function whose scope is purely within another function.
You simply can't do this in C.
Yet here I have a program which compiles without a peep under gcc4.2.1
(with -ansi -Wall, no less), AND runs correctly, but which icc
(10.1.015) won't touch with a ten-foot-pole:
=====begin sample program=====
#include <stdio.h>
int main()
{
int sub1()
{
printf("1");
return(0);
}
int sub2()
{
printf("2\n");
return(0);
}
/* start of main */
sub1();
sub2();
}
=======end sample program========
I don't see anything wrong with this. Nevertheless, icc aborts the
compilation with the fatal error
testit.c(6): error: expected a ";"
{
^
It doesn't like the opening left-brace of "sub1".
Now, I've read this group before, and I know I'm going to get reamed
for such a simple question, but: what's wrong? And why does one
compiler pass it and the other doesn't?
Which one takes it? Must be a non-conforming one then.
This is in openSuse 10.3 on a 2.5GHz core 2 duo with 3GB RAM (though
none of that matters).
Thanks in advance,
Bye, Jojo
Joachim Schmitz wrote:
Ronald Bruck wrote:
>Sigh. It's been awhile since I've programmed in C, but I'm SURE that you can have a function whose scope is purely within another function. You simply can't do this in C.
>Yet here I have a program which compiles without a peep under gcc4.2.1 (with -ansi -Wall, no less), AND runs correctly, but which icc (10.1.015) won't touch with a ten-foot-pole:
=====begin sample program===== #include <stdio.h>
int main() { int sub1() { printf("1"); return(0); } int sub2() { printf("2\n"); return(0); } /* start of main */ sub1(); sub2(); } =======end sample program========
I don't see anything wrong with this. Nevertheless, icc aborts the compilation with the fatal error
testit.c(6): error: expected a ";" { ^
It doesn't like the opening left-brace of "sub1".
Now, I've read this group before, and I know I'm going to get reamed for such a simple question, but: what's wrong? And why does one compiler pass it and the other doesn't?
Which one takes it? Must be a non-conforming one then.
Ah, I see, gcc. Add -pedantic to switch off that non-standard extension
>This is in openSuse 10.3 on a 2.5GHz core 2 duo with 3GB RAM (though none of that matters).
Thanks in advance,
Bye, Jojo
Ronald Bruck <br***@math.usc.eduwrote:
Sigh. It's been awhile since I've programmed in C, but I'm SURE that
you can have a function whose scope is purely within another function.
Only as a compiler specific extension. I guess you're mixing that
up with the posibility to declare (but not define) a function
within another function.
Yet here I have a program which compiles without a peep under gcc4.2.1
(with -ansi -Wall, no less),
Add '-pedantic' to the mix and it will tell you
z6.c:6: warning: ISO C forbids nested functions
z6.c:11: warning: ISO C forbids nested functions
AND runs correctly, but which icc
(10.1.015) won't touch with a ten-foot-pole:
So icc does not support this extension (at least not per
default as gcc does).
=====begin sample program=====
#include <stdio.h>
int main()
{
int sub1()
{
printf("1");
return(0);
}
int sub2()
{
printf("2\n");
return(0);
}
/* start of main */
sub1();
sub2();
}
=======end sample program========
I don't see anything wrong with this. Nevertheless, icc aborts the
compilation with the fatal error
testit.c(6): error: expected a ";"
{
^
It doesn't like the opening left-brace of "sub1".
Also gcc starts complaining about that line if you make it
really standard compliant with '-pedantic'. All allowed at
this place is a ';' to end the declaration of the function.
But the '{' starts a function definition instead.
Regards, Jens
--
\ Jens Thoms Toerring ___ jt@toerring.de
\__________________________ http://toerring.de
"Joachim Schmitz" <no*********@schmitz-digital.dewrites:
Ronald Bruck wrote:
>Sigh. It's been awhile since I've programmed in C, but I'm SURE that you can have a function whose scope is purely within another function.
You simply can't do this in C.
Nonsense. Of course you can do this in C. Non "standard" extensions are
still "C" I am afraid.
Ronald Bruck wrote:
>
Sigh. It's been awhile since I've programmed in C, but I'm SURE
that you can have a function whose scope is purely within another
function. Yet here I have a program which compiles without a peep
under gcc4.2.1 (with -ansi -Wall, no less), AND runs correctly,
but which icc (10.1.015) won't touch with a ten-foot-pole:
.... snip ...
>
Now, I've read this group before, and I know I'm going to get
reamed for such a simple question, but: what's wrong? And why
does one compiler pass it and the other doesn't?
Because you were using a non-standard extension of gcc. Local
functions are forbidden in standard C. If you run gcc properly
(with gcc -W -Wall -ansi -pedantic) so that it restricts itself to
standard C, it will reject that program too.
--
[mail]: Chuck F (cbfalconer at maineline dot net)
[page]: <http://cbfalconer.home.att.net>
Try the download section.
** Posted from http://www.teranews.com **
Richard wrote:
"Joachim Schmitz" <no*********@schmitz-digital.dewrites:
>Ronald Bruck wrote:
>>Sigh. It's been awhile since I've programmed in C, but I'm SURE that you can have a function whose scope is purely within another function.
You simply can't do this in C.
Nonsense. Of course you can do this in C. Non "standard" extensions are
still "C" I am afraid.
Nonsense. And if you're afraid, cower.
--
Eric Sosman es*****@ieee-dot-org.invalid
Eric Sosman <es*****@ieee-dot-org.invalidwrites:
Richard wrote:
>"Joachim Schmitz" <no*********@schmitz-digital.dewrites:
>>Ronald Bruck wrote: Sigh. It's been awhile since I've programmed in C, but I'm SURE that you can have a function whose scope is purely within another function. You simply can't do this in C.
Nonsense. Of course you can do this in C. Non "standard" extensions are still "C" I am afraid.
Nonsense. And if you're afraid, cower.
So people using nested functions are not writing C?
Don't be so ridiculous.
Oh, and tell IBM. http://publib.boulder.ibm.com/infoce..._functions.htm
On Sat, 31 May 2008 12:49:01 -0400, CBFalconer wrote:
Because you were using a non-standard extension of gcc. Local functions
are forbidden in standard C. If you run gcc properly (with gcc -W -Wall
-ansi -pedantic) so that it restricts itself to standard C, it will
reject that program too.
That's just plain wrong. If you had actually bothered to try it, you would
have found that gcc with your recommended options accepts the original
code (as permitted).
$ gcc -W -Wall -ansi -pedantic testit.c -o testit
testit.c: In function ‘main’:
testit.c:5: warning: ISO C forbids nested functions
testit.c:10: warning: ISO C forbids nested functions
testit.c:18: warning: control reaches end of non-void function
$ ./testit
12
Implementations aren't required to reject code with syntax errors or
constraint violations. GCC with your recommended options doesn't. This is
intentional, conforming, and documented.
Richard wrote:
Eric Sosman <es*****@ieee-dot-org.invalidwrites:
>Richard wrote:
>>"Joachim Schmitz" <no*********@schmitz-digital.dewrites:
Ronald Bruck wrote: Sigh. It's been awhile since I've programmed in C, but I'm SURE that you can have a function whose scope is purely within another function. You simply can't do this in C. Nonsense. Of course you can do this in C. Non "standard" extensions are still "C" I am afraid.
Nonsense. And if you're afraid, cower.
So people using nested functions are not writing C?
No, no more than those who write `GOTO 10' are writing C.
Don't be so ridiculous.
Don't be daft.
Oh, and tell IBM.
http://publib.boulder.ibm.com/infoce..._functions.htm
Quoting from the above: "The language feature is an
extension to C89 and C99, implemented to facilitate porting
programs developed with GNU C."
--
Eric Sosman es*****@ieee-dot-org.invalid
Eric Sosman <es*****@ieee-dot-org.invalidwrites:
Richard wrote:
>Eric Sosman <es*****@ieee-dot-org.invalidwrites:
>>Richard wrote: "Joachim Schmitz" <no*********@schmitz-digital.dewrites:
Ronald Bruck wrote: >Sigh. It's been awhile since I've programmed in C, but I'm SURE that >you can have a function whose scope is purely within another function. You simply can't do this in C. Nonsense. Of course you can do this in C. Non "standard" extensions are still "C" I am afraid. Nonsense. And if you're afraid, cower.
So people using nested functions are not writing C?
No, no more than those who write `GOTO 10' are writing C.
>Don't be so ridiculous.
Don't be daft.
>Oh, and tell IBM.
http://publib.boulder.ibm.com/infoce..._functions.htm
Quoting from the above: "The language feature is an
extension to C89 and C99, implemented to facilitate porting
programs developed with GNU C."
I realise from your posting history that you like to be picky and
obstructive, but I am afraid they ARE writing C. It might not be "ISO
compliant C" (or whatever) but it is still C.
So Gnu supports them. IBM compilers them. Hey! Ring them up and tell
them it is "not C". It is C. Their C. Live with it.
Richard wrote:
Eric Sosman <es*****@ieee-dot-org.invalidwrites:
>Richard wrote:
>>Eric Sosman <es*****@ieee-dot-org.invalidwrites:
Richard wrote: "Joachim Schmitz" <no*********@schmitz-digital.dewrites: > >Ronald Bruck wrote: >>Sigh. It's been awhile since I've programmed in C, but I'm SURE that >>you can have a function whose scope is purely within another function. >You simply can't do this in C. Nonsense. Of course you can do this in C. Non "standard" extensions are still "C" I am afraid. Nonsense. And if you're afraid, cower. So people using nested functions are not writing C?
No, no more than those who write `GOTO 10' are writing C.
>>Don't be so ridiculous.
Don't be daft.
>>Oh, and tell IBM.
http://publib.boulder.ibm.com/infoce..._functions.htm
Quoting from the above: "The language feature is an extension to C89 and C99, implemented to facilitate porting programs developed with GNU C."
I realise from your posting history that you like to be picky and
obstructive, but I am afraid they ARE writing C. It might not be "ISO
compliant C" (or whatever) but it is still C.
So Gnu supports them. IBM compilers them. Hey! Ring them up and tell
them it is "not C". It is C. Their C. Live with it.
The programming language C is defined by an International
Standard. Implementations behave as that Standard requires;
when they don't, it's a bug.
Gadgets like nested functions are defined with varying
degrees of specificity and completeness, by the whims of the
implementors who choose to provide them. If implementations
differ incompatibly concerning the details of how such a
gadget behaves, each of the various providers will tell you
it's a feature.
The IBM quote you dug up explicitly describes the feature
as quote an extension to C89 and C99 endquote, not as part of
the C language. Re-read it -- and, in your words, live with it.
--
Eric Sosman es*****@ieee-dot-org.invalid
Eric Sosman <es*****@ieee-dot-org.invalidwrote:
Richard wrote:
Eric Sosman <es*****@ieee-dot-org.invalidwrites:
Richard wrote: "Joachim Schmitz" <no*********@schmitz-digital.dewrites:
Ronald Bruck wrote: Sigh. It's been awhile since I've programmed in C, but I'm SURE that you can have a function whose scope is purely within another function. You simply can't do this in C. Nonsense. Of course you can do this in C. Non "standard" extensions are still "C" I am afraid.
Nonsense. And if you're afraid, cower.
So people using nested functions are not writing C?
No, no more than those who write `GOTO 10' are writing C.
Don't be so ridiculous.
Don't be daft.
I don't think it will help if you ask this "Richard" character
not to be. He is and obviously can't help it. Just whistle a
few bars of the Queen's song "Trolls will be trolls" and just
disregard him otherwise;-)
Regards, Jens
--
\ Jens Thoms Toerring ___ jt@toerring.de
\__________________________ http://toerring.de
Harald van D?k wrote:
CBFalconer wrote:
>Because you were using a non-standard extension of gcc. Local functions are forbidden in standard C. If you run gcc properly (with gcc -W -Wall -ansi -pedantic) so that it restricts itself to standard C, it will reject that program too.
That's just plain wrong. If you had actually bothered to try it,
you would have found that gcc with your recommended options
accepts the original code (as permitted).
$ gcc -W -Wall -ansi -pedantic testit.c -o testit
testit.c: In function ‘main’:
testit.c:5: warning: ISO C forbids nested functions
testit.c:10: warning: ISO C forbids nested functions
testit.c:18: warning: control reaches end of non-void function
I'm amused you consider that an acceptable result. Please flag all
your code so we know to avoid it.
--
[mail]: Chuck F (cbfalconer at maineline dot net)
[page]: <http://cbfalconer.home.att.net>
Try the download section.
** Posted from http://www.teranews.com **
CBFalconer <cb********@yahoo.comwrites:
Harald van D?k wrote:
>CBFalconer wrote:
>>Because you were using a non-standard extension of gcc. Local functions are forbidden in standard C. If you run gcc properly (with gcc -W -Wall -ansi -pedantic) so that it restricts itself to standard C, it will reject that program too.
That's just plain wrong. If you had actually bothered to try it, you would have found that gcc with your recommended options accepts the original code (as permitted).
$ gcc -W -Wall -ansi -pedantic testit.c -o testit testit.c: In function ‘main’: testit.c:5: warning: ISO C forbids nested functions testit.c:10: warning: ISO C forbids nested functions testit.c:18: warning: control reaches end of non-void function
I'm amused you consider that an acceptable result. Please flag all
your code so we know to avoid it.
The point is that a conforming compiler is merely required to issue a
diagnostic; it's not required to reject the program, which is what you
asserted. By printing a warning, gcc fullfilled the requirements of
the standard.
Harald didn't say he considered it "an acceptable result", merely that
it doesn't violate the standard.
A conforming C implementation is not required to *reject* any program
that doesn't use "#error".
--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
Nokia
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
Joachim Schmitz said:
<snip>
Which [compiler] takes [nested functions]? Must be a non-conforming
one then.
Conforming implementations are required to diagnose programs that contain
at least one syntax error or constraint violation (and nested functions
certainly qualify), but they are not required to reject them. Nested
functions are a perfectly legal extension.
--
Richard Heathfield <http://www.cpax.org.uk>
Email: -http://www. +rjh@
Google users: <http://www.cpax.org.uk/prg/writings/googly.php>
"Usenet is a strange place" - dmr 29 July 1999
Richard Heathfield wrote:
Joachim Schmitz said:
<snip>
>Which [compiler] takes [nested functions]? Must be a non-conforming one then.
Conforming implementations are required to diagnose programs that contain
at least one syntax error or constraint violation (and nested functions
certainly qualify), but they are not required to reject them. Nested
functions are a perfectly legal extension.
Yes, when gcc is concerned.
When lcc-win does something similar the polemic never ends.
--
jacob navia
jacob at jacob point remcomp point fr
logiciels/informatique http://www.cs.virginia.edu/~lcc-win32
jacob navia said:
Richard Heathfield wrote:
>Joachim Schmitz said:
<snip>
>>Which [compiler] takes [nested functions]? Must be a non-conforming one then.
Conforming implementations are required to diagnose programs that contain at least one syntax error or constraint violation (and nested functions certainly qualify), but they are not required to reject them. Nested functions are a perfectly legal extension.
Yes, when gcc is concerned.
Where *any* conforming implementation is concerned.
When lcc-win does something similar the polemic never ends.
Any conforming implementation may offer extensions, provided that they
don't break strictly conforming programs and provided that any syntax
errors or constraint violations result in at least one diagnostic message.
If lcc-win conforms to ISO C, it may offer extensions. And if it doesn't,
it is not bound by the requirements of the Standard in any case, so it's
hard to see what you're complaining about. It's equally hard to see why
you're complaining about it *here*. I suggest you take up the matter in
comp.compilers.lcc, where discussion of the lcc compiler is topical.
--
Richard Heathfield <http://www.cpax.org.uk>
Email: -http://www. +rjh@
Google users: <http://www.cpax.org.uk/prg/writings/googly.php>
"Usenet is a strange place" - dmr 29 July 1999 This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Rajesh Garg |
last post by:
Can we have private constructors and destructors? IF yes what is the
use of such constructors or destructors.....in the sense where can
these be implemented in a system.................
I have...
|
by: Bob Rock |
last post by:
Hello,
in the last few days I've made my first few attempts at creating mixed C++
managed-unmanaged assemblies and looking aftwerwards with ILDASM at what is
visible in those assemblies from a...
|
by: Andrew Poulos |
last post by:
I having some trouble understanding how to make functions private
I have created an instance of an object using a constructor function and
there are 4 prototypes:
Comm = function() {
//blah...
|
by: __PPS__ |
last post by:
Hello everybody, today I had another quiz question
"if class X is privately derived from base class Y what is the scope of
the public, protected, private members of Y will be in class X"
By...
|
by: harry |
last post by:
Hi ppl
I have a question about memory layout of a class. Consider the code
below:
class Base1 {
virtual void f() { cout << "Base1::f" << endl; }
virtual void g() { cout << "Base1::g" <<...
| |
by: John Goche |
last post by:
Hello,
page 202 of Symbian OS Explained by Jo Stichbury states
"All virtual functions, public, protected or private, should be
exported"
then page 203 states
"In the rare cases where a...
|
by: v4vijayakumar |
last post by:
Why we need "virtual private member functions"? Why it is not an
(compile time) error?
|
by: PragueExpat |
last post by:
I (think) that I've come up with a pattern that I haven't seen in any
publications so far and I would like some feedback. Basically, I was
looking for a way to inherit private functions and I came...
|
by: Peng Yu |
last post by:
Hi,
I'm wondering if there is something in namespace like the 'private'
keyword in class?
I want to define some class or function that can only be used within
that namespace.
Thanks,
Peng
|
by: Vijay Meena |
last post by:
Hi,
Private functions can be virtual in C++ ( unlike Java) ? What is the
use of private virtual functions ? Below is the code -
#include <iostream>
class Foo {
public:
virtual void test()...
|
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,...
| |
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...
|
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,...
|
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...
|
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,...
|
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...
|
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: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
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...
| |