|
|
|
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 9:11 PM, Josh Triplett <josh@xxxxxxxxxxxxxxxx> wrote:
> 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:
>> >> /* 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.
Maybe I did not investigate deeply enough to find out the origin of
the warnings.
But I get no warnings/errors, when I disable CHECK_TYPE in C++ code.
> What warning do you encounter about CHECK_TYPE?
In the following code1 (file main.cc):
int main(int argc, char* argv[])
{
struct string_list *files=NULL;
void* file_void;
char* file_char;
struct symbol_list *symbols=NULL;
struct symbol_list *all_symbols=NULL;
symbols=sparse_initialize(argc, argv, &files);
concat_symbol_list(symbols, &all_symbols);
FOR_EACH_PTR_NOTAG(files, file_void) { // line 19
file_char=(char*)file_void;
symbols=sparse(file_char);
concat_symbol_list(symbols, &all_symbols);
} END_FOR_EACH_PTR_NOTAG(file_void);
exit(EXIT_SUCCESS);
}
I get:
main.cc: In function ‘int main(int, char**)’:
main.cc:19: error: comparison between distinct pointer types ‘void*’
and ‘char*’ lacks a cast
compiler and (important) flags:
g++ (GCC) 4.2.4 (Ubuntu 4.2.4-1ubuntu4), -Wall -Werror
Now, the code2 (file main.cc):
int main(int argc, char* argv[])
{
struct string_list *files=NULL;
char* file_char;
struct symbol_list *symbols=NULL;
struct symbol_list *all_symbols=NULL;
symbols=sparse_initialize(argc, argv, &files);
concat_symbol_list(symbols, &all_symbols);
FOR_EACH_PTR_NOTAG(files, file_char) { // line 18
symbols=sparse(file_char);
concat_symbol_list(symbols, &all_symbols);
} END_FOR_EACH_PTR_NOTAG(file_char);
exit(EXIT_SUCCESS);
}
I get error:
main.cc: In function ‘int main(int, char**)’:
main.cc:18: error: invalid conversion from ‘void*’ to ‘char*’
sparse headers included (in both code examples):
#ifdef __cplusplus
extern "C" {
#endif
#include <sparse/allocate.h>
#include <sparse/expression.h>
#include <sparse/lib.h>
#include <sparse/linearize.h>
#include <sparse/token.h>
#include <sparse/parse.h>
#include <sparse/symbol.h>
#ifdef __cplusplus
}
#endif
Tomas Klacko
--
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
[Newbies FAQ] [Kernel List] [Site Home] [IETF Annouce] [DCCP] [Netdev] [Networking] [Security] [Bugtraq] [Photo] [Yosemite] [MIPS Linux] [ARM Linux] [Linux Security] [Linux RAID] [Linux SCSI] [DDR & Rambus] [Trinity Fuzzer Tool]