* ISO C90 compilation error
@ 2024-02-29 7:03 Paz Offer
2024-02-29 7:14 ` Thomas Huth
2024-02-29 7:59 ` Daniel P. Berrangé
0 siblings, 2 replies; 4+ messages in thread
From: Paz Offer @ 2024-02-29 7:03 UTC (permalink / raw)
To: qemu-devel@nongnu.org
[-- Attachment #1: Type: text/plain, Size: 608 bytes --]
Hi,
I am trying to build my code with QEMU and getting compilation error according to the ISO C90 standard:
const size_t buf_size = 31;
char buffer[buf_size + 1];
error: ISO C90 forbids array ‘buffer’ whose size can’t be evaluated [-Werror=vla]
I noticed that the code builds with '-std=gnu11', which is newer then C90, so this is not clear to me why I get this error.
Where is the correct place to specify the language version for this?
I am building QEMU using the instructions on QEMU site (configure, make).
Thanks,
Paz
[-- Attachment #2: Type: text/html, Size: 4088 bytes --]
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: ISO C90 compilation error
2024-02-29 7:03 ISO C90 compilation error Paz Offer
@ 2024-02-29 7:14 ` Thomas Huth
2024-02-29 7:59 ` Daniel P. Berrangé
1 sibling, 0 replies; 4+ messages in thread
From: Thomas Huth @ 2024-02-29 7:14 UTC (permalink / raw)
To: Paz Offer, qemu-devel@nongnu.org; +Cc: Peter Maydell
On 29/02/2024 08.03, Paz Offer wrote:
> Hi,
>
> I am trying to build my code with QEMU and getting compilation error
> according to the /ISO C90 /standard:
>
> const size_t buf_size = 31;
> char buffer[buf_size + 1];
>
> error: ISO C90 forbids array ‘buffer’ whose size can’t be evaluated
> [-Werror=vla]
>
> I noticed that the code builds with '-std=gnu11', which is newer then C90,
> so this is not clear to me why I get this error.
> Where is the correct place to specify the language version for this?
The "ISO C90" part of the error message is quite misleading here. It's
rather that we explicitly enabled -Werror=vla in our codebase recently:
https://gitlab.com/qemu-project/qemu/-/commit/64c1a5443528ac09d8cd50f365d6
See the commit description there for the rationale.
Thomas
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: ISO C90 compilation error
2024-02-29 7:03 ISO C90 compilation error Paz Offer
2024-02-29 7:14 ` Thomas Huth
@ 2024-02-29 7:59 ` Daniel P. Berrangé
2024-02-29 9:41 ` Philippe Mathieu-Daudé
1 sibling, 1 reply; 4+ messages in thread
From: Daniel P. Berrangé @ 2024-02-29 7:59 UTC (permalink / raw)
To: Paz Offer; +Cc: qemu-devel@nongnu.org
On Thu, Feb 29, 2024 at 07:03:35AM +0000, Paz Offer wrote:
> Hi,
>
> I am trying to build my code with QEMU and getting compilation error according to the ISO C90 standard:
>
> const size_t buf_size = 31;
> char buffer[buf_size + 1];
>
> error: ISO C90 forbids array ‘buffer’ whose size can’t be evaluated [-Werror=vla]
>
> I noticed that the code builds with '-std=gnu11', which is newer then
> C90, so this is not clear to me why I get this error.
> Where is the correct place to specify the language version for this?
QEMU has set compiler flags to explicitly /forbid/ use of variable
sized arrays on the stack, as it is a known dangerous language
feature. You must refactor your changes to avoid this by using either
a statically sized array, or allocating on the heap.
With regards,
Daniel
--
|: https://berrange.com -o- https://www.flickr.com/photos/dberrange :|
|: https://libvirt.org -o- https://fstop138.berrange.com :|
|: https://entangle-photo.org -o- https://www.instagram.com/dberrange :|
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: ISO C90 compilation error
2024-02-29 7:59 ` Daniel P. Berrangé
@ 2024-02-29 9:41 ` Philippe Mathieu-Daudé
0 siblings, 0 replies; 4+ messages in thread
From: Philippe Mathieu-Daudé @ 2024-02-29 9:41 UTC (permalink / raw)
To: Daniel P. Berrangé, Paz Offer; +Cc: qemu-devel@nongnu.org
On 29/2/24 08:59, Daniel P. Berrangé wrote:
> On Thu, Feb 29, 2024 at 07:03:35AM +0000, Paz Offer wrote:
>> Hi,
>>
>> I am trying to build my code with QEMU and getting compilation error according to the ISO C90 standard:
>>
>> const size_t buf_size = 31;
>> char buffer[buf_size + 1];
>>
>> error: ISO C90 forbids array ‘buffer’ whose size can’t be evaluated [-Werror=vla]
>>
>> I noticed that the code builds with '-std=gnu11', which is newer then
>> C90, so this is not clear to me why I get this error.
>> Where is the correct place to specify the language version for this?
>
> QEMU has set compiler flags to explicitly /forbid/ use of variable
> sized arrays on the stack, as it is a known dangerous language
> feature. You must refactor your changes to avoid this by using either
> a statically sized array, or allocating on the heap.
If you array has a fixed size, you could use a definition, so the
proprocessor can evaluate the buffer size:
#define BUF_SIZE 31
char buffer[BUF_SIZE + 1];
Regards,
Phil.
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2024-02-29 9:42 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-02-29 7:03 ISO C90 compilation error Paz Offer
2024-02-29 7:14 ` Thomas Huth
2024-02-29 7:59 ` Daniel P. Berrangé
2024-02-29 9:41 ` Philippe Mathieu-Daudé
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).