andy5995 / canfigger

A lightweight library designed to parse configuration files
https://andy5995.github.io/canfigger/
GNU General Public License v3.0
9 stars 1 forks source link

Build fails on Windows #31

Open andy5995 opened 2 weeks ago

andy5995 commented 1 week ago

So I've made some changes, some progress. But now when I try this code:

  const size_t chunkSize = 1024;
  char *buffer = NULL;
  size_t bufferSize = 0;
  size_t bytesRead;

  do
  {
    char tempBuffer[chunkSize];

And the compilation fails:

../canfigger.c(290): error C2057: expected constant expression
../canfigger.c(290): error C2466: cannot allocate an array of constant size 0
../canfigger.c(290): error C2133: 'tempBuffer': unknown size

So... 1024 isn't a constant??

I guess I'll take a break from this. I'm not sure I want to spend so much time supporting the msvc compiler. I just work on my projects for fun.

Does anyone have a reasonable explanation for 1024 not being a constant?

I asked ChatGPT about this:

MSVC expects array sizes to be constant expressions known at compile time. While the code you shared does specify chunkSize as const, it doesn’t consider this as a compile-time constant. To fix this, you can use a #define for chunkSize instead, making it a true constant for MSVC:

lol