qemu-ppc
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [PATCH 07/23] hw/block/nvme: Use definition to avoid dynamic stack a


From: Richard Henderson
Subject: Re: [PATCH 07/23] hw/block/nvme: Use definition to avoid dynamic stack allocation
Date: Fri, 7 May 2021 08:59:18 -0700
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.7.1

On 5/5/21 2:10 PM, Philippe Mathieu-Daudé wrote:
The compiler isn't clever enough to figure 'SEG_CHUNK_SIZE' is
a constant! Help it by using a definitions instead.

This isn't about being clever or not, it's semantics.

In C++, "const int" is a proper constant, but in C it is a variable with a constant value. Thus the use of the symbol in the array bounds is, by definition, variable.


-    const int SEG_CHUNK_SIZE = 256;
+#define SEG_CHUNK_SIZE 256

enum { SEG_CHUNK_SIZE = 256 };

would retain the function scope for the symbol, if that's desirable.


r~



reply via email to

[Prev in Thread] Current Thread [Next in Thread]