473,756 Members | 5,656 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Reason for ISO ; warning

[Warning] ISO C does not allow extra ';' outside of a function

int n;;

int main(void)
{
....
}

Anyone care to enlighten me as to why ISO C does not allow this, but
apparently ANSI c99 does?

Ta

Dec 7 '05
22 4061
Simon Biber wrote:

Wolfgang Riedel wrote:
so this should be valid
(and compiles with -Wall -pedantic -std=c99):

#include <string.h>

size_t blah = strlen("abc");

/*...*/


It's not valid, and gcc produces the diagnostic message "initialize r
element is not constant"
when compiled with exactly the options you give.


C99
6.7.8 Initialization

[#4] All the expressions in an initializer for an object
that has static storage duration shall be constant
expressions or string literals.

6.6 Constant expressions

[#7] More latitude is permitted for constant expressions in
initializers. Such a constant expression shall be, or
evaluate to, one of the following:
-- an arithmetic constant expression,
-- a null pointer constant,
-- an address constant, or
-- an address constant for an object type plus or minus an
integer constant expression.

[#8] An arithmetic constant expression shall have arithmetic
type and shall only have operands that are integer
constants, floating constants, enumeration constants,
character constants, and sizeof expressions.

--
pete
Dec 8 '05 #21
Simon Biber wrote:

Wolfgang Riedel wrote:
so this should be valid (and compiles with -Wall -pedantic -std=c99):

#include <string.h>

size_t blah = strlen("abc");

/*...*/


It's not valid, and gcc produces the diagnostic message "initialize r
element is not constant" when compiled with exactly the options you give.

--
Simon.


You snipped the rationale, I quoted.
I think it's correct (evaluates to arithmetic constant exrpssion).

Btw. my gcc doesn't warn (maybe not the latest & greatest):
gcc --version

gcc (GCC) 3.2.2
Copyright (C) 2002 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

cat z2.c && gcc -Wall -pedantic -std=c99 -o z2 z2.c && echo $? && ./z2

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
static int bah = strlen("abc");
int
main(void)
{
printf("%d\n", bah);
exit(0);
}
0
3
Dec 8 '05 #22
Wolfgang Riedel wrote:
Simon Biber wrote:
Wolfgang Riedel wrote:
so this should be valid (and compiles with -Wall -pedantic -std=c99):

#include <string.h>

size_t blah = strlen("abc");

/*...*/ It's not valid, and gcc produces the diagnostic message "initialize r
element is not constant" when compiled with exactly the options you give.

--
Simon.


You snipped the rationale, I quoted.
I think it's correct (evaluates to arithmetic constant exrpssion).

No. The relevant definition is

"An arithmetic constant expression shall have arithmetic type and shall only
have operands that are integer constants, floating constants, enumeration
constants, character constants, and sizeof expressions. Cast operators in an
arithmetic constant expression shall only convert arithmetic types to
arithmetic types, except as part of an operand to a sizeof operator whose
result is an integer constant."

'strlen("abc")' doesn't qualify. gcc is free to evaluate 'strlen("abc")' as
a constant expression, but this does not make it an arithmetic constant
expression. Of course, the initializer to "blah" need only be a constant
expression. It doesn't have to be an arithmetic constant expression
specifically.
Btw. my gcc doesn't warn (maybe not the latest & greatest):

<snip>
Not a bug. Later versions of gcc do warn because standards-conforming
compilers are not required to accept the program, but gcc does not violate
the standard by not issuing a diagnostic -- implementations are expressly
allowed to accept other forms of expressions as constant than the ones
described by the standard.

If you expect 'strlen("abc")' to be a constant expression, you're relying on
an extension. It's not portable code.

Note that gcc does *not* allow expressions that cannot be evaluated at
compile time as initializers, and rightly so. This will not compile:

size_t foo();
size_t blah = foo();

S.
Dec 8 '05 #23

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

Similar topics

4
5837
by: acemann7 | last post by:
Windows 2000 udb v 7.2 Got the latest fixpak 13 Applied it. Still can't get a single java sp to run. I used to get reason "2"... now reason "0" - reason 0 is not even documented. I point jdk11_path to: Java Development Kit 1.1 installation path (JDK11_PATH) =
3
2574
by: Bill Burris | last post by:
How do I find what is causing this warning from the Linker? If I use /NODEFAULTLIB I get hundreds of undefined symbols. LINK : warning LNK4098: defaultlib 'MSVCRT' conflicts with use of other libs; use /NODEFAULTLIB:library Here is the compiler options: /Od /I "C:\DriverX4\Include" /I "..\ThreadLib" /AI "..\Utility\bin\Debug" /AI "..\Logging\bin\Debug" /AI "Debug" /D "WIN32" /D "_DEBUG" /D "_WINDLL"
3
7221
by: DJTN | last post by:
I'm getting the following error when I try to compile my setup project in VS 2002. I have re-installed the .net framework 1.1 and it didnt solve the problem. WARNING: Unable to find dependency 'mscorlib' (Signature='B77A5C561934E089' Version='1.0.5000.0') of assembly 'System.dll' WARNING: Unable to find dependency 'mscorlib' (Signature='B77A5C561934E089' Version='1.0.5000.0') of assembly 'System.Windows.Forms.dll' WARNING: Unable to...
0
274
by: pemo | last post by:
ISO C does not allow extra ';' outside of a function int n;; int main(void) { .... } Anyone care to enlighten me as to why ISO C does not allow this, but
1
2003
by: spanov | last post by:
i've got problem installing python-2.3.5 from sources on FreeBSD 5.3 root@server# ./configure > conf_log configure: WARNING: curses.h: present but cannot be compiled configure: WARNING: curses.h: check for missing prerequisite headers? configure: WARNING: curses.h: see the Autoconf documentation configure: WARNING: curses.h: section "Present But Cannot Be Compiled" configure: WARNING: curses.h: proceeding with the...
16
21798
by: gumby | last post by:
I'm having trouble getting HADR to work with the sample databases on two HS20 xSeries blades, Red Hat ES4 up3, DB2 8.2.4, getting the following error. SQL1768N Unable to start HADR. Reason code = "7" - The primary database failed to establish a connection to its standby database within the HADR timeout interval. What things should I check besides the remote host and remote service parameters on the standby database, which seem to be...
1
5031
by: Lennart | last post by:
While investigating deadlocks in an application I wrote a function to check if there where any batchjobs running in parallell at the time of the deadlocks. The check runs surprisingly fast, but If I narrow the searchspace I start getting SQL0437W with reason code 3 "Optimizer cost underflow". Statistics are up to date on the table. Is this something to worry about, or can the warning be ignored? /Lennart
11
1699
by: Siddhu | last post by:
Hai, i am student & i have struck up with the following program's output. Kindly help me to reason out why the output goes as which is given below. THE PROGRAM goes as; #include<iostream.h> #include<conio.h> void main() { int i=0,x={1,2,3,4,5},y={5,4,3,2,1},r={0,0,0,0,0}; while(i++<5)
92
6239
by: Heinrich Pumpernickel | last post by:
what does this warning mean ? #include <stdio.h> int main() { long l = 100; printf("l is %li\n", l * 10L);
0
9454
marktang
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...
0
9271
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
9868
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
9707
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
8709
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
6533
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
5139
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
5301
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3352
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.