From: Josh Triplett <josh@joshtriplett.org>
To: Tomas Klacko <tomas.klacko@gmail.com>
Cc: Christopher Li <sparse@chrisli.org>, linux-sparse@vger.kernel.org
Subject: Re: including sparse headers in C++ code
Date: Mon, 11 Oct 2010 16:37:07 -0700 [thread overview]
Message-ID: <20101011233706.GA10991@feather> (raw)
In-Reply-To: <AANLkTi=8EkK+_9pOA8fbDgYGfz-bPGj6XhLUnfSkdGeV@mail.gmail.com>
On Tue, Oct 12, 2010 at 12:33:32AM +0200, Tomas Klacko wrote:
> On Sat, Oct 9, 2010 at 11:46 PM, Christopher Li <sparse@chrisli.org> wrote:
> > On Sat, Oct 9, 2010 at 1:59 PM, Josh Triplett <josh@joshtriplett.org> wrote:
> >> It seems reasonable to avoid the use of C++ keywords in Sparse *headers*
> >> (though unnecessary in *source*). Looks like this will primarily cause
> >> pain due to "enum namespace" and the various places using it. Seems
> >> easy enough to change those all to "ns". "new" mostly seems to get used
> >> as a parameter name or local variable name; for the former we could omit
> >> it, and for the latter we could trivially call it something more
> >> specific like "newlist" or "newptr".
> >>
> >> So, I'd tend to guess "patches welcome" (again, for headers only, plus
> >> minimal corresponding source changes when required). I wouldn't
> >> anticipate other Sparse developers objecting strongly, but if they do
> >> your mail seems like the right way to find out. The various reasons
> >> given for *not* making the Linux kernel headers compatible don't seem to
> >> apply here, though.
> >
> > Well said. I don't expect sparse to compile in the C++ mode. Making
> > sparse header usable in C++ seems reasonable to me.
>
> Great. I am posting my current status (as a patch) so that you can comment on it
> and that I can refine it further.
> --- a/c2xml.c
> +++ b/c2xml.c
> @@ -128,7 +128,7 @@ static void examine_modifiers(struct symbol *sym,
> xmlNodePtr node)
>
> int i;
>
> - if (sym->namespace != NS_SYMBOL)
> + if (sym->Namespace != NS_SYMBOL)
How about "ns"?
> --- a/compile-i386.c
> +++ b/compile-i386.c
> @@ -332,9 +332,9 @@ busy:
> return 1;
> }
>
> -static struct storage *get_reg(struct regclass *class)
> +static struct storage *get_reg(struct regclass *Class)
Just call it "regclass".
> --- a/evaluate.c
> +++ b/evaluate.c
> @@ -357,7 +357,7 @@ static inline int classify_type(struct symbol
> *type, struct symbol **base)
> return type_class[type->type];
> }
>
> -#define is_int(class) ((class & (TYPE_NUM | TYPE_FLOAT)) == TYPE_NUM)
> +#define is_int(Class) ((Class & (TYPE_NUM | TYPE_FLOAT)) == TYPE_NUM)
"c" or "cls"?
> --- a/expression.c
> +++ b/expression.c
> @@ -118,7 +118,7 @@ static struct token *parse_type(struct token
> *token, struct expression **tree)
> struct symbol *sym;
> *tree = alloc_expression(token->pos, EXPR_TYPE);
> (*tree)->flags = Int_const_expr; /* sic */
> - token = typename(token, &sym, NULL);
> + token = Typename(token, &sym, NULL);
"type_name"?
> --- a/lib.h
> +++ b/lib.h
> @@ -120,6 +120,10 @@ extern int Wdeclarationafterstatement;
> extern int dbg_entry;
> extern int dbg_dead;
>
> +#ifdef __cplusplus
> +extern "C" {
> +#endif
> +
> @@ -162,33 +170,41 @@ static inline void free_instruction_list(struct
> instruction_list **head)
> free_ptr_list((struct ptr_list **)head);
> }
>
> -static inline struct instruction * delete_last_instruction(struct
> instruction_list **head)
> +static inline struct instruction * delete_last_instruction(
> + struct instruction_list **head)
Huh? I don't see a change here, just formatting (and what looks like
whitespace damage).
> {
> - return undo_ptr_list_last((struct ptr_list **)head);
> + return (struct instruction *)undo_ptr_list_last(
> + (struct ptr_list **)head);
> }
Wow. I had to double-check this because I couldn't quite believe C++
had that degree of dain bramage, but sure enough:
/tmp$ cat test.c
extern void *pv(void);
int *pi(void)
{
return pv();
}
/tmp$ gcc -c test.c -o /dev/null
/tmp$ g++ -c test.c -o /dev/null
test.c: In function ‘int* pi()’:
test.c:5: error: invalid conversion from ‘void*’ to ‘int*’
(1) /tmp$
I can understand C++ having stronger typechecking, but void pointers
*exist* for this purpose. *Really* debatable whether Sparse should work
around this. Avoiding keywords, sure, but casting void pointers
everywhere? People *remove* these kinds of casts from C programs as a
cleanup.
- Josh Triplett
--
To unsubscribe from this list: send the line "unsubscribe linux-sparse" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
next prev parent reply other threads:[~2010-10-11 23:37 UTC|newest]
Thread overview: 41+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-10-09 16:40 including sparse headers in C++ code Tomas Klacko
2010-10-09 20:59 ` Josh Triplett
2010-10-09 21:46 ` Christopher Li
2010-10-10 11:41 ` Bernd Petrovitsch
2010-10-10 11:52 ` Kamil Dudka
2010-10-11 9:44 ` Bernd Petrovitsch
2010-10-11 16:04 ` Christopher Li
2010-10-11 19:12 ` Josh Triplett
2010-10-13 14:45 ` Bernd Petrovitsch
2010-10-18 18:43 ` Christopher Li
2010-10-20 7:29 ` Al Viro
2010-10-20 9:39 ` Bernd Petrovitsch
2010-10-20 15:34 ` Christopher Li
2010-10-29 13:22 ` Bernd Petrovitsch
2010-11-05 0:57 ` Christopher Li
2010-11-09 13:28 ` Bernd Petrovitsch
2010-11-09 22:52 ` Christopher Li
2010-11-10 10:52 ` Bernd Petrovitsch
2010-10-11 22:33 ` Tomas Klacko
2010-10-11 22:46 ` Al Viro
2010-10-11 23:01 ` Christopher Li
2010-10-12 22:45 ` Tomas Klacko
2010-10-13 0:37 ` Christopher Li
2010-10-13 11:39 ` Bernd Petrovitsch
2010-10-16 16:03 ` Tomas Klacko
2010-10-16 19:11 ` Josh Triplett
2010-10-17 10:31 ` Tomas Klacko
2010-10-18 4:13 ` Christopher Li
2010-10-18 5:39 ` Josh Triplett
2010-10-18 18:37 ` Christopher Li
2010-10-19 20:03 ` Tomas Klacko
2010-10-19 21:31 ` Al Viro
2010-10-19 21:46 ` David Malcolm
2010-10-19 22:12 ` Al Viro
2010-10-19 22:49 ` Tomas Klacko
2010-10-20 10:19 ` Bernd Petrovitsch
2010-10-19 23:07 ` Christopher Li
2010-10-20 7:40 ` Al Viro
2010-10-18 3:16 ` Christopher Li
2010-10-11 23:37 ` Josh Triplett [this message]
2010-10-12 10:42 ` Bernd Petrovitsch
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20101011233706.GA10991@feather \
--to=josh@joshtriplett.org \
--cc=linux-sparse@vger.kernel.org \
--cc=sparse@chrisli.org \
--cc=tomas.klacko@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.