473,385 Members | 1,483 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,385 software developers and data experts.

Variables are accepted as the subscription when declare a array

It is strange. Happen to get following the fragment compiled
successfully. Is there anything wrong with my compiler or my mind?

Please guide me to correct my understanding on it.

Sincerely,

lovecreatesbeauty
$ cat p113.c
int main(void)
{
int len = 100;
int a[len];
}
$ gcc --version
gcc (GCC) 4.1.0
Copyright (C) 2006 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.

$ gcc -std=c89 p113.c
$ gcc -std=c99 p113.c
$

Apr 7 '06 #1
3 1364
"lovecreatesbeauty" <lo***************@gmail.com> writes:
It is strange. Happen to get following the fragment compiled
successfully. Is there anything wrong with my compiler or my mind?

Please guide me to correct my understanding on it.

$ cat p113.c
int main(void)
{
int len = 100;
int a[len];
} [...]
$ gcc -std=c89 p113.c
$ gcc -std=c99 p113.c
$


gcc isn't a conforming compiler unless you ask it nicely to act as
one.

% gcc -std=c89 p113.c
% gcc -std=c89 -pedantic p113.c
p113.c: In function `main':
p113.c:4: warning: ISO C90 forbids variable-size array `a'
%

--
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.
Apr 7 '06 #2
Keith Thompson wrote:

"lovecreatesbeauty" <lo***************@gmail.com> writes:
It is strange. Happen to get following the fragment compiled
successfully. Is there anything wrong with my compiler or my mind?

Please guide me to correct my understanding on it.

$ cat p113.c
int main(void)
{
int len = 100;
int a[len];
}
[...] gcc isn't a conforming compiler unless you ask it nicely to act as
one.

% gcc -std=c89 p113.c
% gcc -std=c89 -pedantic p113.c
p113.c: In function `main':
p113.c:4: warning: ISO C90 forbids variable-size array `a'

[...]

Is it really non-conforming? Are variable-sized arrays "forbidden", or
is it not part of the standard, but allowable as an extension?

--
+-------------------------+--------------------+-----------------------------+
| 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>

Apr 7 '06 #3
Kenneth Brody wrote:
Keith Thompson wrote:

"lovecreatesbeauty" <lo***************@gmail.com> writes:
It is strange. Happen to get following the fragment compiled
successfully. Is there anything wrong with my compiler or my mind?

Please guide me to correct my understanding on it.

$ cat p113.c
int main(void)
{
int len = 100;
int a[len];
}

[...]
gcc isn't a conforming compiler unless you ask it nicely to act as
one.

% gcc -std=c89 p113.c
% gcc -std=c89 -pedantic p113.c
p113.c: In function `main':
p113.c:4: warning: ISO C90 forbids variable-size array `a'

[...]

Is it really non-conforming? Are variable-sized arrays "forbidden", or
is it not part of the standard, but allowable as an extension?


c89 draft
3.5.4.2 Array Declarators:
Constraints:
The expression that specifies the size of an array shall be an integral
constant expression that has a value greater than zero.

The program is non-conforming. A conforming implementation must
provide a diagnostic but may then continue to do what ever it likes as
the behavior is no longer defined.

Robert Gamble

Apr 7 '06 #4

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

Similar topics

13
by: Larry L | last post by:
I have a Module that declares several arrays as public, some string, some integers. I then have 2 forms. Form A is the main form, that loads on start-up, and has a command button to open Form B. On...
16
by: Roland Hall | last post by:
In working with arrays, I have found that I am unable to dimension and array with a variable that has an integer value but I can redimension one this way. I haven't see any information that tells...
4
by: opt_inf_env | last post by:
Hello, I know three ways to pass variables form one page to another. The first one is to declare and set session variable. In this case if one goes to another page (by clicking on hyperlink or...
5
by: elzacho | last post by:
I would like to (and commonly do) define my variables in the most specific scope I can. For example... int foo(int a, int b, int c) { /* don't declare temp here if we can help it */ ... ...
1
by: Roy Gourgi | last post by:
Hi, I am new to C#. I am trying to create some variables and arrays that can be seen throughtout the whole program. I have no choice as they have to be seen by the whole program. Where and how...
1
by: Materialised | last post by:
Hi All, I am trying the follow the following MSDN tutorial: Walkthrough: Authoring a Simple Multithreaded Component with Visual C#...
5
by: Kyote | last post by:
Sorry, but I have no idea how to phrase the subject better than that. I've come across this a few different times and decided to ask in case there's a way to do it. It would simplify things a bit...
18
by: MajorSetback | last post by:
I am using the Redhat version of Linux and GNU C++. It is not clear to me whether this is a Linux issue or a C++ issue. I do not have this problem running the same program on Windows but...
1
by: andrebarn | last post by:
Hi guys I what to create Dynamic variables when I loop through and recordset, I have read this forum : http://bytes.com/forum/thread436288.html But see my problem is that so af the variables need...
1
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...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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...

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.