🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: gnu.g++.bug
Article #834

False incompatable pointer error?

#834
From: Gregory N. Bond
Date: Thu, 20 Aug 1992 06:26
36 lines
2021 bytes
(Novice alert: I am a C programmer, not a C++ programmer, so there may
be some subtle C++ semantic feature here I am not aware of.)

Consider this, a fragment taken from groff-1.03:lib/errarg.c:

leo$ cat -n t.c
     1  // demonstrate error in gcc 2.2.2?
     2
     3  void foo(const char *p)
     4  {
     5          const char *s;
     6
     7          s = p; // OK
     8          s = p ? p : "(Null)"; // OK
     9          s = p == 0 ? "(Null)" : p; // line 9 - fails
    10  }
leo$ g++ -v -c t.c
Reading specs from /usr/local/lib/gcc-lib/sparc-sun-sunos4.1.1/2.2.2/specs
gcc version 2.2.2
 /usr/local/lib/gcc-lib/sparc-sun-sunos4.1.1/2.2.2/cpp -lang-c++ -v -undef -D__GNUC__=2 -D__GNUG__=2 -D__cplusplus -Dsparc -Dsun -Dunix -D__sparc__ -D__sun__ -D__unix__ -D__sparc -D__sun -D__unix t.c /tmp/cca24525.i
GNU CPP version 2.2.2 (sparc)
 /usr/local/lib/gcc-lib/sparc-sun-sunos4.1.1/2.2.2/cc1plus /tmp/cca24525.i -quiet -dumpbase t.cc -version -o /tmp/cca24525.s
GNU C++ version 2.2.2 (sparc) compiled by GNU C version 2.2.2.
t.c: In function `void  foo (const char *)':
t.c:9: assignment between incompatible pointer types
leo$

The exact same file (modulo comment syntax) works under gcc.  Why
should changing the order of the clauses in the ?: statement make it
fail?  And why only in C++?

Greg.
--
Gregory Bond <gnb@bby.com.au> Burdett Buckeridge & Young Ltd Melbourne Australia
``USL has never sold long distance.  You're going after the wrong men in black 
  hats.  (Or, in the case of Plan 9, black space suits)'' - Tom Limoncelli
Technical Details
Message-ID: <GNB.92Aug20162640@duke.bby.com.au>
Path: arc1-ca.pugleaf.net!sparky!uunet!usc!zaphod.mps.ohio-state.edu!cis.ohio-state.edu!bby.COM.AU!gnb

Show Full Headers
Complete Article Headers
Newsgroups: gnu.g++.bug
Path: arc1-ca.pugleaf.net!sparky!uunet!usc!zaphod.mps.ohio-state.edu!cis.ohio-state.edu!bby.COM.AU!gnb
From: gnb@bby.COM.AU (Gregory N. Bond)
Subject: False incompatable pointer error?
Message-ID: <GNB.92Aug20162640@duke.bby.com.au>
Sender: gnulists@ai.mit.edu
Organization: Burdett, Buckeridge & Young, Melbourne, Australia
Distribution: gnu
Date: Thu, 20 Aug 1992 06:26:40 GMT
Approved: bug-g++@prep.ai.mit.edu
Lines: 38