Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Importing absolute symbols as constexpr

23 views
Skip to first unread message

Marcel Mueller

unread,
Apr 13, 2017, 10:31:50 AM4/13/17
to
AFAIK the address of an external symbol with static linkage can be used
as constexpr (e.g. a method reference as template parameter).

Is it also possible to import /absolute/ linker symbols this way?

Example

shader.o:
00000000 R shader
00000410 A shader_size

shader.h:
// import the shader symbol from shader.o, OK
extern unsigned shader[];

// Try to import shader_size - does not work
extern const int shader_size;
constexpr int shader_size_proxy = (int)&shader_size;
#define shader_size shader_size_proxy

// without constexpr
const int shader_size_proxy2 = (int)&shader_size;
#undef shader_size
#define shader_size shader_size_proxy2


The basic problem is that C++ only imports addresses but not absolute
values like the global symbol shader_size. And the following required
conversion from int* to int is no longer a valid constexpr.

Is there anything to come around this restriction?


Marcel

Alf P. Steinbach

unread,
Apr 13, 2017, 12:24:55 PM4/13/17
to
Why can't you just provide the definition in a header file?


Cheers!,

- Alf


Marcel Mueller

unread,
Apr 13, 2017, 4:55:53 PM4/13/17
to
On 13.04.17 18.24, Alf P. Steinbach wrote:
> Why can't you just provide the definition in a header file?

Of course, I can generate a matching header with hard coded constants.
But C++ compilation time on a Pi 1 is pure pain. So I favor just to link
the executable when the GPU code changes.


Marcel

Ian Collins

unread,
Apr 13, 2017, 6:14:23 PM4/13/17
to
Use a cross-compiler?

--
Ian
0 new messages