-3

How to make a compilation successful for a program with a variable length array?(currently, Showing error : Variable sized array). I am using gcc in linux. How to make compiler compatible to c99 standard ? PLease help me in this. THanks in advance.

4
  • 1
    With a new enough version of GCC it will automatically use a later version of the C standard. Which version are you using? What are you trying to do? Please edit your question to include a minimal reproducible example of your code, together with a full and complete copy-paste (as text) of your errors (with comments added in the code where you get the errors). Commented Jul 6, 2020 at 4:44
  • Also please take some time to read the help pages, take the SO tour, read How to Ask, as well as this question checklist. Commented Jul 6, 2020 at 4:45
  • 3
    it would have been faster to read the diagnostic message that tells you what to do, than write this question ... Commented Jul 6, 2020 at 4:45
  • @M.M Usually a VLA warning is just to hint that one uses VLAs in their code. It does not tell you what to do to satisfy the compiler. If you don't know what a VLA is nor what its advantages or disadvantages are you got a problem. Asking for that is absolutely appropriate. Commented Jul 6, 2020 at 7:57

2 Answers 2

4

How to make compiler compatible to c99 standard?

By default, the compiler defaults to the most compatible version of C version is installed. Do define the compilation version explicitly, compile the program with the following command-line:

$ gcc -std=c99 -o my_program my_program.c

By defining the -std=c99, the compiler will be using C99 standard.

Edit: If you're still getting the warning and not the error, then you need to provide your code to know what exactly is wrong.

Sign up to request clarification or add additional context in comments.

11 Comments

Yes , I tried it . Still no changes in the result. Thank You!!!
@DhanaPrakaash Then you need to show your code, we don't exactly know what your code does and the -std=c99 flag must work correctly. Also, edit the question and add all the information after typing gcc -v command in your terminal.
@RohanBari Even with -std=c99 the warning won't go away. The compiler is just hinting.
@RobertSsupportsMonicaCellio the VLAs are supported in C99 standard, ain't it?
|
0

"How to make a compilation successful for a program with a variable length array? (currently, Showing error : Variable sized array)."

Usually it isn't an error to compile a code with a VLA unless you compile with -Werror flag.

The diagnostic you get is high-probably "only" a warning that you use a VLA inside of it, which is risky.

Thus, the compiler informs you about that.

So, you indeed can compile a program with VLAs without any error.

If you got errors they must belong to anything else. We can't find those out since you showed no specific code.

Take a look at this question of mine, not so long ago (even if it is for Clang, it covers the same topic as the answers suggest that a compiler is free to complain about whatever it likes):

Why does clang complain about using variable-length arrays with '-std=c99' flag?

All useful information you can find there.

VLAs are not portable. Try to use alternatives, for example dynamically allocated arrays by using malloc().

Related:


"How to make compiler compatible to (the) C99 standard?"

As Rohan in his answer already said, you can use the -std-c99 flag at the invocation of gcc for that. But it probably won't solve your problem to do so.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.