Arch Linux

Please read this before reporting a bug:
https://wiki.archlinux.org/title/Bug_reporting_guidelines

Do NOT report bugs when a package is just outdated, or it is in the AUR. Use the 'flag out of date' link on the package page, or the Mailing List.

REPEAT: Do NOT report bugs for outdated packages!
Tasklist

FS#23472 - gcc compile error

Attached to Project: Arch Linux
Opened by wanglihe (Hermeswang) - Monday, 28 March 2011, 08:53 GMT
Last edited by Allan McRae (Allan) - Monday, 28 March 2011, 09:24 GMT
Task Type Bug Report
Category Upstream Bugs
Status Closed
Assigned To No-one
Architecture All
Severity Low
Priority Normal
Reported Version
Due in Version Undecided
Due Date Undecided
Percent Complete 100%
Votes 1
Private No

Details

Description:

静态数组长度使用常量表示时,gcc无法编译,但是clang正常。
gcc can not compile souce code when array using const number,but clang can do.


Additional info:
* package version(s)
gcc --version
gcc (GCC) 4.5.2 20110127 (prerelease)
Copyright © 2010 Free Software Foundation, Inc.
本程序是自由软件;请参看源代码的版权声明。本软件没有任何担保;
包括没有适销性和某一专用目的下的适用性担保。
clang --version
clang version 2.8 (branches/release_28)
Target: x86_64-unknown-linux-gnu
Thread model: posix

* config and/or log files etc.


Steps to reproduce:

use gcc and clang compile the file. -std=c99 or -std=c89

or this source

const int NUMBER = 1024 * 8;
int main(int argc,char* argv[]) {
static char buf[NUMBER];
return 0;
}



This task depends upon

Closed by  Allan McRae (Allan)
Monday, 28 March 2011, 09:24 GMT
Reason for closing:  Not a bug
Comment by Allan McRae (Allan) - Monday, 28 March 2011, 09:24 GMT
From: http://stackoverflow.com/questions/1476847/integer-constants-in-c-define-versus-static-const-int-x-1234

In C, a const variable isn't a "real" compile-time constant... it's really just a normal variable that you're not allowed to modify. Because of this, you can't use a const int variable to specify the size of an array.

Now, gcc has an extension that allows you to specify the size of an array at runtime if the array is created on the stack. This is why, when you leave off the static from the definition of x, the code compiles. However, this would still not be legal in standard C.

Loading...