- 
                Notifications
    You must be signed in to change notification settings 
- Fork 6
Open
Labels
bugSomething isn't workingSomething isn't workingconfirmedThis issue or pull request is confirmed to be done.This issue or pull request is confirmed to be done.
Description
CThreads commit
Description
The function cthreads_error_string does not compile on any compilers that do not support variable-length array (VLA).
VLAs are part of the C99 standard but seems to be only supported by GCC and Clang (cppreference.com).
suggested solutions
- static size array using #define CTHREADS_ERROR_MSG_SIZE [Some reasonable size]
- malloc based on size_t length
- If you want to keep VLA for GCC and Clang and still support other compilers:
#if defined(__GNUC__) || defined(__clang__)
    #define VLA_SUPPORTED 1
#else
    #define VLA_SUPPORTED 0
#endif
//Implement 2 functions based on if VLA is supported or notSteps to reproduce
Compile CThreads using MSVC.
Example code
> cl /TC /W4 /DCTHREADS_DEBUG test.c cthreads.c
Microsoft (R) C/C++ Optimizing Compiler Version 19.42.34436 for x86
Copyright (C) Microsoft Corporation.  All rights reserved.
test.c
C:\prog\CThreads\cthreads.h(460): error C2057: expected constant expression
C:\prog\CThreads\cthreads.h(460): error C2466: cannot allocate an array of constant size 0
cthreads.c
C:\prog\CThreads\cthreads.h(460): error C2057: expected constant expression
C:\prog\CThreads\cthreads.h(460): error C2466: cannot allocate an array of constant size 0
cthreads.c(465): error C2057: expected constant expression
cthreads.c(465): error C2466: cannot allocate an array of constant size 0
Generating Code...
//Line 460 in cthreads.h
size_t cthreads_error_string(size_t length, char buf[length], int error_code);Confirmations
- My environment meets the minimum requirements.
- I have verified that this is not a duplicate issue.
Metadata
Metadata
Assignees
Labels
bugSomething isn't workingSomething isn't workingconfirmedThis issue or pull request is confirmed to be done.This issue or pull request is confirmed to be done.