Error Initializer Element Is Not Constant
Contents |
here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and policies of this site About Us Learn error initializer element is not constant struct more about Stack Overflow the company Business Learn more about hiring developers or posting
Error Initializer Element Is Not Constant C
ads with us Stack Overflow Questions Jobs Documentation Tags Users Badges Ask Question x Dismiss Join the Stack Overflow Community error initializer element is not constant malloc Stack Overflow is a community of 4.7 million programmers, just like you, helping each other. Join them; it only takes a minute: Sign up Initializer element is not constant in C [duplicate] up vote error initializer element is not constant gcc 9 down vote favorite 1 Possible Duplicate: Error “initializer element is not constant” when trying to initialize variable with const I'm coming from javascript/php/python and probably I'm missing something, here is the code: const int a = 50; const int c = 100; const int d = 100; int endX = c + a; int endY = d; int startX, startY, b; I get ex1.4.c:6: error: initializer element
Error Initializer Element Is Not Constant Stderr
is not constant ex1.4.c:7: error: initializer element is not constant Someone has an explanation? c share|improve this question edited Dec 28 '12 at 2:41 cpx 7,5351154101 asked Oct 5 '12 at 16:58 nick 3,66162757 marked as duplicate by Jens Gustedt, Tim Cooper, Steve Jessop, alk, Alexey Frunze Oct 5 '12 at 18:00 This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question. 1 look at the panel on the right of this question this has been asked many times before. Please search this site before asking. –Jens Gustedt Oct 5 '12 at 17:01 I can compile your code just fine. what compiler/system are you using? –gokcehan Oct 5 '12 at 17:04 @gokcehan: are you using a C++ compiler, by any chance? –Steve Jessop Oct 5 '12 at 17:10 @SteveJessop nope, just wrapped them all in main and compiled with gcc main.c. –gokcehan Oct 5 '12 at 17:15 @gokcehan: ah, the questioner's code isn't in main, it's at file scope. –Steve Jessop Oct 5 '12 at 17:16 | show 1 more comment 5 Answers 5 active oldest votes up vot
here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and policies of this site About Us Learn more about Stack Overflow the company Business Learn more about hiring developers extern initializer element is not constant or posting ads with us Stack Overflow Questions Jobs Documentation Tags Users Badges Ask Question x c const initializer element is not constant Dismiss Join the Stack Overflow Community Stack Overflow is a community of 4.7 million programmers, just like you, helping each other. Join them; it
Initializer Of Is Not A Constant Expression
only takes a minute: Sign up “Initializer element is not constant” error for no reason in Linux GCC, compiling C [duplicate] up vote 8 down vote favorite 2 This question already has an answer here: Error “initializer element is not http://stackoverflow.com/questions/12750796/initializer-element-is-not-constant-in-c constant” when trying to initialize variable with const 4 answers I take my main.c file and compile it with gcc -std=c1x -c main.c in Mac OS X, and it works fine with no errors. Then I do the exact same thing in LinuxMint and on a Raspberry Pi, and in both cases, it gives me errors about "initializer element is not constant". One example of a problematic line with relevant code: //STATIC GLOBAL CONSTANTS const unsigned long long LATITUDE = http://stackoverflow.com/questions/21592494/initializer-element-is-not-constant-error-for-no-reason-in-linux-gcc-compilin (long) 3600000; const unsigned long long LONGITUDE = (long) 1810000; const unsigned long long MAX_COORDINATES_NUMBER = (LATITUDE-1) + LATITUDE*(LONGITUDE-1); //compiler error: initializer element is not constant It's supposed to let me do arithmetic, right? I could just replace that with the actual numbers, and it would work, but then it would become messy. And it works fine on my Mac anyway. Is there some option in GCC I have to specify on Linux (besides -std=c1x, which you also don't need on Mac)? c linux osx gcc share|improve this question asked Feb 6 '14 at 1:52 sudo 1,26921327 marked as duplicate by alkc Users with the c badge can single-handedly close c questions as duplicates and reopen them as needed. May 21 '15 at 17:55 This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question. 3 This is just a C thing. Per C11 6.6.6, integer constant expressions must only have operands that are constants, or sizeof and _Alignof expressions, and your first two variables here are not constants. I'm not sure why clang allows this, although 6.6.10 does say an implementation is allowed to accept other forms of constant expressions. The arithmetic is fine - if you replace those first two statements with #defines, or enums, it'll work as you'd expect. –Paul Griffiths Feb 6 '14 at 2:27 @PaulGriffiths That
Login: [x] User account creation filtered due to spam. Bug38354 - Spurious error: initializer element is not computable at load time Summary: Spurious error: initializer element is not computable at load time Status: UNCONFIRMED Alias: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=38354 None Product: gcc Classification: Unclassified Component: c (show other bugs) Version: 4.3.2 Importance: P3 normal http://cboard.cprogramming.com/c-programming/98546-initializer-element-not-constant.html Target Milestone: --- Assignee: Not yet assigned to anyone URL: Keywords: diagnostic Depends on: Blocks: Reported: 2008-12-01 21:04 UTC by Behdad Esfahbod Modified: 2014-09-10 03:10 UTC (History) CC List: 2 users (show) adam gcc-bugs See Also: Host: Target: Build: Known to work: Known to fail: Last reconfirmed: Attachments Add an attachment (proposed patch, testcase, etc.) Note You need to is not log in before you can comment on or make changes to this bug. Description Behdad Esfahbod 2008-12-01 21:04:27 UTC The following code is from gcc docs and works as expected: #include
Programming Boards C Programming initializer element is not constant... Getting started with C or C++ | C Tutorial | C++ Tutorial | C and C++ FAQ | Get a compiler | Fixes for common problems Thread: initializer element is not constant... Thread Tools Show Printable Version Email this Page… Subscribe to this Thread… Display Linear Mode Switch to Hybrid Mode Switch to Threaded Mode 02-01-2008 #1 John Connor View Profile View Forum Posts Registered User Join Date Jan 2008 Posts 20 initializer element is not constant... Hi I'm trying to compile the following code, but gcc 4.2 returns the messages "global.c:8: error: initializer element is not constant" "global.c:9: error: initializer element is not constant" Code: #include