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

__builtin_offsetof macro

28 views
Skip to first unread message

jacobnavia

unread,
Sep 3, 2015, 10:06:48 AM9/3/15
to
Consider this error:

./DiskIndex.h:430:65: error: expected ')'

<<__builtin_offsetof(DiskIndex_LeafNode<T>,DiskIndex_LeafNode<T>::BranchCount)
^
./DiskIndex.h:430:24: note: to match this '('

<<__builtin_offsetof(DiskIndex_LeafNode<T>,DiskIndex_LeafNode<T>::BranchCount)
^

The code is trying to figure out the offset of "BranchCount" within the
class "DiskIndex_LeafNode" (all this in template form of course).

WHAT could be wrong with this?

jacob

P.S. This was compiling OK some years ago. (gcc-4.4.3) Now I am
compiling with

Apple LLVM version 6.1.0 (clang-602.0.53) (based on LLVM 3.6.0svn)


Thanks in advance folks.

P.S. The code of course does NOT use the __builtin directly. It uses
stddef.h offsetof macro that expand to __builtin_offsetof

Victor Bazarov

unread,
Sep 3, 2015, 10:32:19 AM9/3/15
to
On 9/3/2015 10:06 AM, jacobnavia wrote:
> Consider this error:
>
> ./DiskIndex.h:430:65: error: expected ')'
>
> <<__builtin_offsetof(DiskIndex_LeafNode<T>,DiskIndex_LeafNode<T>::BranchCount)
>
> ^
> ./DiskIndex.h:430:24: note: to match this '('
>
> <<__builtin_offsetof(DiskIndex_LeafNode<T>,DiskIndex_LeafNode<T>::BranchCount)
>
> ^
>
> The code is trying to figure out the offset of "BranchCount" within the
> class "DiskIndex_LeafNode" (all this in template form of course).
>
> WHAT could be wrong with this?

It is possible you don't need to prepend 'BranchCount' with the name of
the class since you already supply it as the first argument.

>
> jacob
>
> P.S. This was compiling OK some years ago. (gcc-4.4.3) Now I am
> compiling with
>
> Apple LLVM version 6.1.0 (clang-602.0.53) (based on LLVM 3.6.0svn)
>
>
> Thanks in advance folks.
>
> P.S. The code of course does NOT use the __builtin directly. It uses
> stddef.h offsetof macro that expand to __builtin_offsetof

V
--
I do not respond to top-posted replies, please don't ask

Öö Tiib

unread,
Sep 3, 2015, 10:41:37 AM9/3/15
to
Without seeing minimal example of *your* code that does not
compile it is rather hard to tell what is wrong with it. WHAT
could be wrong with that are ...

* that 'DiskIndex_LeafNode<T>' is not completely defined at
the spot of 'offsetof' since definitions have moved during
refactoring.

* that 'DiskIndex_LeafNode<T>' is not a standard layout class
for example since that T is not standard layout but is
something else.

* your code does contain some odd non-standard construct
instead of 'offsetof(DiskIndex_LeafNode<T>,BranchCount)'

* some other thing like that.

Hopefully it helps you somehow.

jacobnavia

unread,
Sep 3, 2015, 10:45:17 AM9/3/15
to
Le 03/09/2015 16:32, Victor Bazarov a écrit :
> On 9/3/2015 10:06 AM, jacobnavia wrote:
>> Consider this error:
>>
>> ./DiskIndex.h:430:65: error: expected ')'
>>
>> <<__builtin_offsetof(DiskIndex_LeafNode<T>,DiskIndex_LeafNode<T>::BranchCount)
>>
>>
>> ^
>> ./DiskIndex.h:430:24: note: to match this '('
>>
>> <<__builtin_offsetof(DiskIndex_LeafNode<T>,DiskIndex_LeafNode<T>::BranchCount)
>>
>>
>> ^
>>
>> The code is trying to figure out the offset of "BranchCount" within the
>> class "DiskIndex_LeafNode" (all this in template form of course).
>>
>> WHAT could be wrong with this?
>
> It is possible you don't need to prepend 'BranchCount' with the name of
> the class since you already supply it as the first argument.
>
> V


YES!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

and

THANKS!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

and again

THANKS!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

Gosh, I am working on this from this morning 11:00 AM and it is now 16:40.

You saved my day. Really.


Thank you again.

jacob


jacobnavia

unread,
Sep 3, 2015, 10:45:27 AM9/3/15
to
Le 03/09/2015 16:32, Victor Bazarov a écrit :
> On 9/3/2015 10:06 AM, jacobnavia wrote:
>> Consider this error:
>>
>> ./DiskIndex.h:430:65: error: expected ')'
>>
>> <<__builtin_offsetof(DiskIndex_LeafNode<T>,DiskIndex_LeafNode<T>::BranchCount)
>>
>>
>> ^
>> ./DiskIndex.h:430:24: note: to match this '('
>>
>> <<__builtin_offsetof(DiskIndex_LeafNode<T>,DiskIndex_LeafNode<T>::BranchCount)
>>
>>
>> ^
>>
>> The code is trying to figure out the offset of "BranchCount" within the
>> class "DiskIndex_LeafNode" (all this in template form of course).
>>
>> WHAT could be wrong with this?
>
> It is possible you don't need to prepend 'BranchCount' with the name of
> the class since you already supply it as the first argument.
>

jacobnavia

unread,
Sep 3, 2015, 10:53:34 AM9/3/15
to
Thanks for your answer Mr Tiib. Actually it was the problem that Mr
Bazarov told me: I was repeating the name of the class.

I learned a lot today, for instance that this is actually a macro that
will sometimes work and sometimes not, depending on the fact that the
class has or not virtual functions. I was misled by that fact (that
appears when you google a bit) and tried to figure out if any of those
classes had a virtual component. But since this appears in the middle of
lenghty template definition that made me fall into total despair...

How could I know if the template expansion would yield a class with non
constant offsets? (i.e. class with virtual fields)?

But after some hours I noticed that this was an error in the SYNTAX
(missing ')') so I got some hope again and asked in this forum.

Thank you all.

jacob

David Brown

unread,
Sep 3, 2015, 2:13:22 PM9/3/15
to
Sometimes it is easy to try too hard to look for a complex answer to a
problem, when it is actually quite simple. And then when you've got the
answer, you don't know whether to laugh at how easy it is, or cry about
the wasted time. (Been there, done that.)

In this case, it is nothing more than the standard C offsetof() macro,
which gcc (and llvm) implements with a builtin function, and you don't
need to give the name of the struct (or class) in the second parameter.


0 new messages