develooper Front page | perl.perl5.porters | Postings from April 2007

C++, void context and side effects

Thread Next
From:
Nicholas Clark
Date:
April 10, 2007 13:30
Subject:
C++, void context and side effects
Message ID:
20070410203008.GK69960@plum.flirble.org
With Sun's C++ compiler on Solaris I can't build perl. I get a SEGV in

    sv_setpvn(get_sv("\"", TRUE), " ", 1);

(near the start of S_init_predump_symbols) because in sv_setpvn, sv is NULL.
This should not be. It's NULL because:

stopped in S_gv_init_sv at line 294 in file "gv.c"
  294           (void)GvSVn(gv);
(dbx) print gv
gv = 0x265550
(dbx) print gv->sv_u.svu_gp
gv->sv_u.svu_gp = 0x275560
(dbx) print *(gv->sv_u.svu_gp)
*gv->sv_u.svu_gp = {
    gp_sv       = (nil)
    gp_io       = (nil)
    gp_cv       = (nil)
    gp_cvgen    = 0
    gp_refcnt   = 1U
    gp_hv       = (nil)
    gp_av       = (nil)
    gp_form     = (nil)
    gp_egv      = 0x265550
    gp_line     = 0
    gp_file_hek = 0x247fec
}
(dbx) step
stopped in S_gv_init_sv at line 297 in file "gv.c"
  297   }
(dbx) print *(gv->sv_u.svu_gp) 
*gv->sv_u.svu_gp = {
    gp_sv       = (nil)
    gp_io       = (nil)
    gp_cv       = (nil)
    gp_cvgen    = 0
    gp_refcnt   = 1U
    gp_hv       = (nil)
    gp_av       = (nil)
    gp_form     = (nil)
    gp_egv      = 0x265550
    gp_line     = 0
    gp_file_hek = 0x247fec
}


where:

#define GvSVn(gv)	(*(GvGP(gv)->gp_sv ? \
			 &(GvGP(gv)->gp_sv) : \
			 &(GvGP(gv_SVadd(gv))->gp_sv)))


So for some reason, the evaluation of the ternary is being ignored by the C++
compiler, presumably because it's in void context. Is that legal, given that
the expression in ternary has side effects?

This is Sun C++ 5.8 2005/10/13

Nicholas Clark

Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About