1

Yeah, so I’m new to C, and I came across an error when dealing with the following code:

typedef struct{ int head; int length; Customer customer[MAX_LENGTH]; } CustomerCi; 

And the error that came out was:

error: variably modified 'customer' at the file scope

How can I fix this?

3
  • i tried those and some of them didnt work and others i didnt understand fully Commented Nov 29, 2013 at 20:08
  • They aren't good duplicate targets (and one of them is for Objective-C). The one for C is Variably modified array at file scope in C. Commented Jul 29, 2023 at 9:12
  • See also the linked questions. Commented Jul 29, 2023 at 12:16

1 Answer 1

1

Replace MAX_LENGTH with a literal value:

#define MAX_LENGTH 32 

for example.

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

6 Comments

yeah it works then but later on i need the value of MAX_LENGTH to be able to change.
the line before the ones i gave already defines MAX_LENGTH as "static const int MAX_LENGTH = 100;"
You can not change the size of an array in C. Either use pointers with malloc/free or use a linked list.
oh ok because i was trying to use it to gauge the size of my queue
@user3050546: In C, static const int MAX_LENGTH = 100; is still regarded as a 'variable' and MAX_LENGTH cannot be used where a constant is required (for example, in case labels, or in array bounds at file scope). In C++, it would be usable like that. If you want C++, use it. But in C, you can't do what you tried.
|

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.