From mboxrd@z Thu Jan 1 00:00:00 1970 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: fee84,e8ef51420f80a908 X-Google-Attributes: gidfee84,public From: Eric Dumazet Subject: Re: Annoying bug/warning in CXX on Digital Date: 1999/07/30 Message-ID: <37A1D9A6.FD5138C5@cosmosbay.com>#1/1 X-Deja-AN: 507037678 Cache-Post-Path: news1!unknown@10.65.0.252 Content-Transfer-Encoding: 7bit References: <37A02650.CA828161@cosmosbay.com> To: "Daniel S. Riley" X-Accept-Language: en Content-Type: text/plain; charset=us-ascii X-Complaints-To: abuse@infonie.fr X-Trace: starship.infonie.fr 933353400 7944 10.1.5.10 (30 Jul 1999 16:50:00 GMT) Organization: Infonie Mime-Version: 1.0 NNTP-Posting-Date: 30 Jul 1999 16:50:00 GMT Newsgroups: comp.unix.osf.osf1 Thanks for your usefull explanations. The problem is that this kind of code is correct : void *memcpy(void *s1, const void *s2, size_t n) ; So "const void *" is different of "void *" a function returning "void *" does say that you can do : char *ptr = memcpy(zone, "hello", 6) ; ptr[3] = 'T' ; but you cannot do : const void *search_in_a_const_zone_first_null(const void *zone) ; char *ptr = search_in_a_const_zone_first_null(zone) ; ptr[1] = 'T' ; egcs -Wall -Wcast-qual for example says that my exemple is correct. HPUX, SOLARIS, Unixware, AIX compilers are OK with this. Now I realise that this warning says 'your const attribute is ignored'. So if I want the compiler checks that const invariance is preserved, I bet that Digital CXX doesn't do the job. It's quite a pity. The solution to hide these warnings is not an option for me. typedef void * Opaque ; typedef const void *const_Opaque ; Opaque MyMemcpy(Opaque, const_Opaque, size_t) ; The solution of having to declare 2 typedefs for each type (with/without the const qualifier) is quite ugly dont you think ? Eric Dumazet "Daniel S. Riley" wrote: > > Eric Dumazet writes: > > # cat bug.C > > typedef void * Opaque ; > > > > const Opaque func(void) > > { > > return 0 ; > > } > > # cxx -c -w0 bug.C > > cxx: Info: bug.C, line 3: type qualifier on return type is meaningless > > const Opaque func(void) > > -------------^ > > As I understand this, the type of "const Opaque" is "void* const" > (const pointer to void), not "const void*" (pointer to const void). > Since "pointer to void" as a return value isn't modifiable, declaring > it const is a no-op--the "const" does nothing, similar to "const int > func()". If the type were "const void*", you wouldn't get the > warning, as the "void" pointed to by the "const void*" is potentially > modifiable, and hence declaring it const means something. > > If that reads like nonsense (and it probably will the first few times), > you need to meditate on the difference between "const pointer to void" > and "pointer to const void". Also try guessing which of these produces > cxx warnings or errors: > > typedef void* Opaque; > > const Opaque f1() { return 0; } > const void* f2() { return 0; } > void* const f3() { return 0; } > const Opaque& f4() { static Opaque i = 0; return i; } > > main() > { > Opaque p1 = f1(); > Opaque p2 = f2(); > Opaque p3 = f3(); > Opaque& p4 = f4(); > } > > > Is there a workaround (to keep the -w0 option but supress this kind of > > warning) > > First, consider whether cxx might be right. The "const" isn't doing > anything--if you thought it was, then you probably want > > typedef const void * Opaque ; > > Opaque func(void) > { > return 0 ; > } > > instead. If you really just want to suppress the warning, here's the > recipe: > > dsr_lnscu4% cxx -c -w0 -msg_display_tag warn.cc > cxx: Warning: warn.cc, line 3: type qualifier on return type is meaningless (D:useless_type_qualifier_on_return_type) > const Opaque func(void) > -------------^ > dsr_lnscu4% cxx -c -w0 -msg_disable useless_type_qualifier_on_return_type warn.cc > dsr_lnscu4% > > or > > dsr_lnscu4% cxx -c -w0 -msg_display_number warn.cc > cxx: Warning: warn.cc, line 3: #824-D type qualifier on return type is meaningless > const Opaque func(void) > -------------^ > dsr_lnscu4% cxx -c -w0 -msg_disable 824 warn.cc > dsr_lnscu4% > > -- > Dan Riley dsr@mail.lns.cornell.edu > Wilson Lab, Cornell University > "History teaches us that days like this are best spent in bed"