RE:Re: pointers in interactive use (fwd)

Pasha Murat (murat@cdfsga.fnal.gov)
Thu, 4 Jun 1998 13:34:00 -0500 (CDT)


Masaharu Goto writes:
> Damir and Pasha,
>
> >Damir Buskulic writes:
> > > Just a strange behaviour. If you do :
> > >
> > > root [0] TH1F* h3("h3","h3",10,0.,1.)
> >
> > just curious : why didn't CINT catch this obvious syntastic error?
> >
> > regards, pasha
>
> I am not checking this. Cint confuses it as
> TH1F* h3(initval);
> and pointer to string "h3","h3".... was used as initializer.
>
> It is possible but no so simple to check. Consider following.
>
> THF1* h1(int a,char b)
> THF1* h2(NULL)
> THF1* h3(h1(1,'c'))
> THF1* h4(("h1","h2",1,(THF1*)0))
> THF1* h5("h1","h2",1,(THF1*)0)
>
> Only the last one is illegal. I'll leave this at this moment.
>
> Masaharu Goto

Dear Masaharu,

if I try to compile the following example (which is equivalent to the Damir's
example above and is even more):
----------------------------------------------------- a.cc
class T {
public:
int t;
T(int i) {t = i;}
};

int main() {
T* t(1);
return 1;
}
--------------------------------------------------------------------------------
the compiler (either SGI CC, gcc or KCC) immediately detects an error
(see the diagnostics below, essentially all the compilers say that one can't
do initialization this way. So let me continue insisting (I could be wrong though)
that Damir gave us an example of wrong syntax which should have been caught by
the compiler/interpreter.
Best regards, Pasha.
--------------------------------------------------------------------------------
/spool/murat>uname -a
IRIX64 cdfsga 6.2 03131016 IP25
/spool/murat>CC -c a.cc
"a.cc", line 8: error(3232): a value of type "int" cannot be used to
initialize an entity of type "T *"
T* t(1);
^

"a.cc", line 8: warning(3262): variable "t" was declared but never referenced
T* t(1);
^

1 error detected in the compilation of "a.cc".
/spool/murat>which KCC
/usr/products/kai/v3_2d/KCC_BASE/bin/KCC
/spool/murat>KCC -c a.cc
"a.cc", line 8: error: a value of type "int" cannot be used to initialize an
entity of type "T *"
T* t(1);
^

"a.cc", line 8: warning: variable "t" was declared but never referenced
T* t(1);
^

1 error detected in the compilation of "a.cc".
/spool/murat>gcc -v
Reading specs from /data61/top/murat/lib/gcc-lib/mips-sgi-irix5.3/2.8.1/specs
gcc version 2.8.1
/spool/murat>gcc -c a.cc
a.cc: In function `int main()':
a.cc:8: warning: initialization to `T *' from `int' lacks a cast
--------------------------------------------------------------------------------