[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~
- Re: [PATCH 06/23] hw/block/dataplane/virtio-blk: Avoid dynamic stack allocation, (continued)
- [PATCH 07/23] hw/block/nvme: Use definition to avoid dynamic stack allocation, Philippe Mathieu-Daudé, 2021/05/05
- Re: [PATCH 07/23] hw/block/nvme: Use definition to avoid dynamic stack allocation, Keith Busch, 2021/05/05
- Re: [PATCH 07/23] hw/block/nvme: Use definition to avoid dynamic stack allocation, Philippe Mathieu-Daudé, 2021/05/05
- Re: [PATCH 07/23] hw/block/nvme: Use definition to avoid dynamic stack allocation, Eric Blake, 2021/05/05
- Re: [PATCH 07/23] hw/block/nvme: Use definition to avoid dynamic stack allocation, Warner Losh, 2021/05/05
- Re: [PATCH 07/23] hw/block/nvme: Use definition to avoid dynamic stack allocation, Keith Busch, 2021/05/05
- Re: [PATCH 07/23] hw/block/nvme: Use definition to avoid dynamic stack allocation, Philippe Mathieu-Daudé, 2021/05/06
- Re: [PATCH 07/23] hw/block/nvme: Use definition to avoid dynamic stack allocation, Richard Henderson, 2021/05/07
Re: [PATCH 07/23] hw/block/nvme: Use definition to avoid dynamic stack allocation, Klaus Jensen, 2021/05/06
Re: [PATCH 07/23] hw/block/nvme: Use definition to avoid dynamic stack allocation,
Richard Henderson <=
[PATCH 08/23] hw/block/nvme: Avoid dynamic stack allocation, Philippe Mathieu-Daudé, 2021/05/05
[PATCH 09/23] hw/net/e1000e_core: Use definition to avoid dynamic stack allocation, Philippe Mathieu-Daudé, 2021/05/05
[PATCH 10/23] hw/ppc/pnv: Avoid dynamic stack allocation, Philippe Mathieu-Daudé, 2021/05/05
[PATCH 11/23] hw/intc/xics: Avoid dynamic stack allocation, Philippe Mathieu-Daudé, 2021/05/05