[ROOT] Difference between CINT and compiler

From: cstrato@EUnet.at
Date: Thu Feb 22 2001 - 23:00:03 MET


Dear Rooters

Since I am testing most of my code as macro before using it in a
library,
I came across the following differences between interpreted and compiled
code:

1, switch statement:
void testcase(const char *vName)
{
   switch(vName) {
   case "name1":
      cout << "ok: " << vName << endl;
      break;
   default:
      cout << "error: " << vName << endl;
   }//switch
}

This code works fine as function testcase("name1") in a macro, however,
the gcc
compiler produces an error, since each case label must be a constant
expression
of an integral type.

2, if statement:
void testif(const char *vName)
{
//only ok in macro
   if (vName == "name1") {
      cout << "ok: " << vName << endl;
   } else {
      cout << "error: " << vName << endl;
   }//if
//ok when compiled
   if (strcmp(vName,"name1") == 0) {
      cout << "ok: " << vName << endl;
   } else {
      cout << "error: " << vName << endl;
   }//if
}

Once again, this code works fine as function testif("name1") in a macro,
it does
also compile without problems, however, the first "if" expression gives
always
"error: name1" while the second "if" expression works as expected.

Why is this difference between CINT and compiled code? Is it necessary?
(It is somehow frustrating to find out that tested code breaks, once it
is compiled)

My system is: LinuxPPC with gcc2.95.2-2a and root 3.00/01

Thank you in advance for your help
Christian
----------------------------------
C.h.r.i.s.t.i.a.n  S.t.r.a.t.o.w.a
V.i.e.n.n.a.  A.U.S.T.R.I.A
e-mail: cstrato@EUnet.at



This archive was generated by hypermail 2b29 : Tue Jan 01 2002 - 17:50:37 MET