sizeof(struct::member)

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

sizeof(struct::member)

Nico Weber
Hi clang folks,

I have this code:

  sockaddr_un sizecheck;  // not used for anything except sizeof.
  const size_t kMaxPipeNameLength = sizeof(sizecheck.sun_path);

Clang warns about |sizecheck| not being used. Do you consider that a bug?

If so, is there some way to write "sizeof(struct::member)" that
doesn't warn in clang?

Thanks,
Nico
_______________________________________________
cfe-dev mailing list
[hidden email]
http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev
Reply | Threaded
Open this post in threaded view
|

Re: sizeof(struct::member)

Chris Lattner

On Sep 20, 2010, at 5:58 PM, Nico Weber wrote:

> Hi clang folks,
>
> I have this code:
>
>  sockaddr_un sizecheck;  // not used for anything except sizeof.
>  const size_t kMaxPipeNameLength = sizeof(sizecheck.sun_path);
>
> Clang warns about |sizecheck| not being used. Do you consider that a bug?
>
> If so, is there some way to write "sizeof(struct::member)" that
> doesn't warn in clang?

Gross, but how about:

sizeof(((yourstruct*)0)->member)

?

-Chris
_______________________________________________
cfe-dev mailing list
[hidden email]
http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev
Reply | Threaded
Open this post in threaded view
|

Re: sizeof(struct::member)

Nico Weber
On Mon, Sep 20, 2010 at 6:06 PM, Chris Lattner <[hidden email]> wrote:

>
> On Sep 20, 2010, at 5:58 PM, Nico Weber wrote:
>
>> Hi clang folks,
>>
>> I have this code:
>>
>>  sockaddr_un sizecheck;  // not used for anything except sizeof.
>>  const size_t kMaxPipeNameLength = sizeof(sizecheck.sun_path);
>>
>> Clang warns about |sizecheck| not being used. Do you consider that a bug?
>>
>> If so, is there some way to write "sizeof(struct::member)" that
>> doesn't warn in clang?
>
> Gross, but how about:
>
> sizeof(((yourstruct*)0)->member)

ಠ_ಠ

But I guess it does the trick.

Thanks!

_______________________________________________
cfe-dev mailing list
[hidden email]
http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev
Reply | Threaded
Open this post in threaded view
|

Re: sizeof(struct::member)

Cory Nelson
In reply to this post by Nico Weber
On Mon, Sep 20, 2010 at 5:58 PM, Nico Weber <[hidden email]> wrote:

> Hi clang folks,
>
> I have this code:
>
>  sockaddr_un sizecheck;  // not used for anything except sizeof.
>  const size_t kMaxPipeNameLength = sizeof(sizecheck.sun_path);
>
> Clang warns about |sizecheck| not being used. Do you consider that a bug?
>
> If so, is there some way to write "sizeof(struct::member)" that
> doesn't warn in clang?

I don't know if Clang supports it yet, but in C++0x it is okay to do
sizeof(struct::member).

--
Cory Nelson
http://int64.org

_______________________________________________
cfe-dev mailing list
[hidden email]
http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev