I read from the book "The Complete Reference - C" that C99 allows us
to declare for loop variables as
for(int i=0; i < 10; i++)
printf("%d",i);
however, my compiler(gcc) gives me the error:
" 'for' loop initial declaration used outside C99 mode "
Please explain. 7 18107
"Ravi" <ra*********@gmail.comschrieb im Newsbeitrag
news:11*********************@q4g2000prc.googlegrou ps.com...
>I read from the book "The Complete Reference - C" that C99 allows us
to declare for loop variables as
for(int i=0; i < 10; i++)
printf("%d",i);
however, my compiler(gcc) gives me the error:
" 'for' loop initial declaration used outside C99 mode "
Please explain.
What's there top explain, the error says it all
In pre C99 this was not possible and if you don't tell your compiler to run
in c99 mode, he rightfully complains.
Bye, Jojo
Ravi wrote:
I read from the book "The Complete Reference - C" that C99 allows us
/C99/ allows us.
to declare for loop variables as
for(int i=0; i < 10; i++)
printf("%d",i);
however, my compiler(gcc) gives me the error:
" 'for' loop initial declaration used outside C99 mode "
"outside C99 mode": not using C99.
Please explain.
Not using C99 =C99 features not available =observed behaviour.
--
BOOM /Tomorrow/ Hedgehog
Nit-picking is best done among friends.
On Sat, 25 Aug 2007 06:37:39 -0700, Ravi wrote:
however, my compiler(gcc) gives me the error:
" 'for' loop initial declaration used outside C99 mode "
Please explain.
GCC defaults to C89. (Or rather, GNU's version.) You need to add
-std=c99 or similar to your compiler's command line.
B.
"Ravi" writes:
>I read from the book "The Complete Reference - C" that C99 allows us
to declare for loop variables as
for(int i=0; i < 10; i++)
printf("%d",i);
however, my compiler(gcc) gives me the error:
" 'for' loop initial declaration used outside C99 mode "
I think it wants you to move the *declaration* of i to the head of the
block containing the for statement.
Ravi wrote:
I read from the book "The Complete Reference - C" that C99 allows us
to declare for loop variables as
for(int i=0; i < 10; i++)
printf("%d",i);
however, my compiler(gcc) gives me the error:
" 'for' loop initial declaration used outside C99 mode "
Please explain.
The diagnostic is clear: you are not in C99 mode and attempting to do
something allowed in C99 but not with earlier standards.
Note that for all versions of C you can do much the same thing just by
introducing a new block:
{
int i;
for(i=0; i < 10; i++)
printf("%d",i);
}
Ravi wrote:
>
I read from the book "The Complete Reference - C" that C99 allows us
to declare for loop variables as
for(int i=0; i < 10; i++)
printf("%d",i);
however, my compiler(gcc) gives me the error:
" 'for' loop initial declaration used outside C99 mode "
Please explain.
By default gcc is in C90 mode. Read its info (or man) docs.
--
Chuck F (cbfalconer at maineline dot net)
Available for consulting/temporary embedded and systems.
<http://cbfalconer.home.att.net>
--
Posted via a free Usenet account from http://www.teranews.com
CBFalconer said:
<snip>
By default gcc is in C90 mode.
No, it isn't. By default, gcc is in gcc mode. You have to kick it
moderately hard to get it into C90 mode.
--
Richard Heathfield <http://www.cpax.org.uk>
Email: -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: Alexander Zatvornitskiy |
last post by:
Hello All!
I'am novice in python, and I find one very bad thing (from my point of view) in
language. There is no keyword or syntax to declare variable, like 'var' in
Pascal, or special syntax in...
|
by: Christophe Grimault |
last post by:
Hi all,
look at the following code:
//////////////////////////
for(int i = 0; i<10; i++)
cout << i;
for(int i = 0; i<20; i++)
cout << i;
|
by: YGeek |
last post by:
Is there any difference between declaring a variable at the top of a method
versus in the code of the method? Is there a performance impact for either
choice? What about if the method will return...
|
by: Alex Vinokur |
last post by:
===========
Windows 2000
Intel C++ 8.0
===========
------ foo.cpp ------
int main ()
{
for (int i = 0; i < 10; i++);
for (int i = 0; i < 10; i++);
|
by: Gaijinco |
last post by:
I have always felt that you should only declared variables as needed,
and implicitily it seems many authors to encourage it, but the other
day a friend told me that declaring variables inside a...
|
by: Kannan |
last post by:
Its been a while I have done pure C programming (I was coding in C++).
Is the following function valid according to standard C?
int main(int argc, char *argv)
{
int x;
x = 9;
printf("Value...
|
by: Pedro Pinto |
last post by:
When compiling my program i got this error:
Error: 'for' loop initial declaration used outside c99 mode
What is it and how can i solve it?
Thanks in advance!
Regards
|
by: Larax |
last post by:
Best explanation of my question will be an example, look below at this
simple function:
function SetEventHandler(element)
{
// some operations on element
element.onclick =
function(event)
{
|
by: Zachary Turner |
last post by:
Hello,
This seems like an extremely basic question, and I'm a bit embarassed
that I can't answer it myself.
I just recently started using GCC and tried to type the following
code:
while...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, we are pleased to welcome back...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, we are pleased to welcome back...
|
by: Vimpel783 |
last post by:
Hello!
Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
|
by: ArrayDB |
last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
|
by: PapaRatzi |
last post by:
Hello,
I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
|
by: CloudSolutions |
last post by:
Introduction:
For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
|
by: Defcon1945 |
last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
|
by: Shællîpôpï 09 |
last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
|
by: af34tf |
last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
| |