Bug 101618 - wl_array_for_each is not C++ compliant
Summary: wl_array_for_each is not C++ compliant
Status: RESOLVED MOVED
Alias: None
Product: Wayland
Classification: Unclassified
Component: wayland (show other bugs)
Version: unspecified
Hardware: Other All
: medium trivial
Assignee: Wayland bug list
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2017-06-28 06:40 UTC by msisov
Modified: 2018-06-08 23:49 UTC (History)
1 user (show)

See Also:
i915 platform:
i915 features:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description msisov 2017-06-28 06:40:18 UTC
Hi,

We've faced an issue, when we used wl_array_for_each in our C++ wayland client implementation.

The problem is that one can't use wl_array_for_each(pos, array) when 
pos is passed as uint32_t*, for example, and array->data is assigned to it. In C++, one cannot just convert void* to other pointer type implicitly as in C.

Is it possible to modify the macro defined to have explicit type cast?

#define wl_array_for_each(pos, array)	\
	for (pos = (uint32_t*) (array)->data; \

or maybe intptr_t before (array)->data ??. 

I'm not sure which one would be better, but it is to you to decide.

Br,
msisov
Comment 1 Daniel Stone 2017-06-28 09:22:20 UTC
It cannot be cast to uint32_t as the type is not known in advance; for example, the modifiers_map request from the text_input protocol uses an array of uint8_t.

Is it possible to do the cast with typeof(*pos)? Every time I think I remember how type-casting works in C++ I'm wrong, so maybe it wouldn't work.
Comment 2 msisov 2017-06-28 12:05:50 UTC
Well, (typeof(pos)) works well, IIRC, C++ doesn't have such a thing like typeof. decltype is used instead. Of course, one can use typeof with C++, but it's rather a compile extension rather than the feature of the language.
Comment 3 msisov 2017-06-28 12:06:16 UTC
Sorry,

s/Well, (typeof(pos)) works well, IIRC,/Well, (typeof(pos)) works well, BUT IIRC,/
Comment 4 GitLab Migration User 2018-06-08 23:49:48 UTC
-- GitLab Migration Automatic Message --

This bug has been migrated to freedesktop.org's GitLab instance and has been closed from further activity.

You can subscribe and participate further through the new bug through this link to our GitLab instance: https://gitlab.freedesktop.org/wayland/wayland/issues/34.


Use of freedesktop.org services, including Bugzilla, is subject to our Code of Conduct. How we collect and use information is described in our Privacy Policy.