KhronosGroup / KhronosGroup/OpenCL-Docs

Variadic Macros Support for OpenCL

Open
#50 11 comments 0 reactions 1 assignee Claimed by @AnastasiaStulova View on GitHub
OpenCL C Spec
Dominant language
Python
Stars
420
Forks
131
Avg merge
5d 13h
Merged PRs (30d)
11

Description

I am wondering why the OpenCL standard forbids variadic macros. They are actually allowed by a couple of OpenCL implementations I have been using, but they are disabled in clang (yielding "error: variadic macros not supported in OpenCL")
I do not understand the reasoning behind disabling variadic macros, in particular since OpenCL compilers usually are based on A C / C++ frontent, which usually has a preprocessor that would actually support variadic macros.

I agree variadic macros do not belong to a modern coding style in the direction of C++20, but I have some code where they are widely used, in particular when you try to have common code segments for different GPU APIs, where you do not have access to the full C++ feature set.

Prime examples are
- Wrappers around printf with some additional checks / functionality (I agree this could also be done with variadic templates nowadays)
- Conditional disabling of parts of the code via defining #define DEBUG(...) to nothing, which is much cleaner than #ifdes everywhere in the code.
- At several places we create some code fragments automatically using macro string concattenation (##) and variadic macros.

My suggestion is to simply allow variadic macros in the code, since they do not increase compiler complexity anyway. At least, there could be an OpenCL extension or in case of clang a compile-time switch to allow variadic macros. My current workaround is to run the .cl file through the -std=c99 frontend of clang for the preprocessor phase and then I am giving the preprocessed file to clang again with -std=c++

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.