Re: including sparse headers in C++ code

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Sat, Oct 16, 2010 at 06:03:53PM +0200, Tomas Klacko wrote:
> On Wed, Oct 13, 2010 at 2:37 AM, Christopher Li <sparse@xxxxxxxxxxx> wrote:
> > On Tue, Oct 12, 2010 at 3:45 PM, Tomas Klacko <tomas.klacko@xxxxxxxxx> wrote:
> >> diff --git a/parse.h b/parse.h
> >> index 6b21e23..f2193e7 100644
> >> --- a/parse.h
> >> +++ b/parse.h
> >> @@ -35,10 +35,12 @@ struct statement {
> >> Â Â Â Â Â Â Â Âstruct /* declaration */ {
> >> Â Â Â Â Â Â Â Â Â Â Â Âstruct symbol_list *declaration;
> >> Â Â Â Â Â Â Â Â};
> >> +#ifndef __cplusplus
> >> Â Â Â Â Â Â Â Âstruct /* label_arg */ {
> >> Â Â Â Â Â Â Â Â Â Â Â Âstruct symbol *label;
> >> Â Â Â Â Â Â Â Â Â Â Â Âstruct statement *label_statement;
> >> Â Â Â Â Â Â Â Â};
> >> +#endif
> >
> > What is this #ifndef Âfor?
> 
> I use it to avoid this error:
> 
> [...]/sparse/parse.h:65: error: declaration of âstatement*
> statement::<anonymous union>::<anonymous struct>::label_statementâ
> [...]sparse/parse.h:41: error: conflicts with previous declaration
> âstatement* statement::<anonymous union>::<anonymous
> struct>::label_statementâ

Huh, interesting.  Turns out that giant union contains two different
structs of the form { struct symbol *, struct statement * }; one for
label_arg and one for labeled_struct.  They have different names for the
symbol, but the same name for the statement.  We should fix that for C
as well, either by renaming one of the statements, or by just making
both variations use the same set of fields and dropping one of the
sub-structs.  Either way, that should happen as an independent patch,
separate from the C++ compatibility changes.

Chris, what do you think?

> >> Â/* Silly type-safety check ;) */
> >> Â#define DECLARE_PTR_LIST(listname,type) Â Â Â Âstruct listname { type *list[1]; }
> >> -#define CHECK_TYPE(head,ptr) Â Â Â Â Â (void)(&(ptr) == &(head)->list[0])
> >> Â#define TYPEOF(head) Â Â Â Â Â Â Â Â Â __typeof__(&(head)->list[0])
> >> Â#define VRFY_PTR_LIST(head) Â Â Â Â Â Â(void)(sizeof((head)->list[0]))
> >>
> >> +#ifndef __cplusplus
> >> +#define CHECK_TYPE(head,ptr) Â Â Â Â Â (void)(&(ptr) == &(head)->list[0])
> >> +#else
> >> +/* I don't know yet how to do this better in C++. */
> >> +#define CHECK_TYPE(head,ptr) (void)((void*)&(ptr) == (void*)&(head)->list[0])
> >> +#endif
> >
> > If you can't get CHECK_TYPE work in C++, you might just make it an empty define
> > instead of doing useless point dancing. At least it is clear that it does not
> > do any thing here.
> 
> True. How about
> #define CHECK_TYPE (head,ptr)   (void)(1)
> ?

As far as I can tell, CHECK_TYPE works just fine in C++.  I could easily
compile an invocation of CHECK_TYPE, as well as some simple examples
that called the macros which invoked CHECK_TYPE.  When I tried
FOR_EACH_PTR, I encountered *other* warnings (related to assigning (void
*) to some other type without a cast), but those warnings didn't come
from CHECK_TYPE.

What warning do you encounter about CHECK_TYPE?

- Josh Triplett
--
To unsubscribe from this list: send the line "unsubscribe linux-sparse" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[Index of Archives]     [Newbies FAQ]     [LKML]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Trinity Fuzzer Tool]

  Powered by Linux