C++ and packed decimal strange behavior

Jevgeni Astanovski <[email protected]>
Newsgroups gmane.comp.lang.as400.c
Message-ID <CAJuVQr3viiDut3MyCG6hW-mGmWTRw5LjUG_CbZ20zk64EaRotw@mail.gmail.com>
Hi, all.
I'm really new with C++ and recently while porting a program from ILE/C to
ILE/C++ ran into a strange effect that I cannot explain. Maybe someone can
help me.

Here's a simple program:

#include <stdlib.h>
#include <bcd.h>

int main (int argc, char *argv[])
{
  char Day1[7], Day2[7] ;
  _DecimalT<15, 0> v1, v2, v3, v4 ;

  memset (Day1, '0', 7) ;
  memset (Day2, '1', 7) ;

  v2 = __D("100") ;
  v3 = __D("10") ;
  v4 = __D("200") ;

  v1 = (memcmp(Day1, Day2, 7) <= 0) ? v2 - v3 - v4 : v2 - v4 ;

  return(0) ;
}

Attempt to compile it produces error message for conditional assignment:
CZP0207 No common type found for operands with type "_DecimalT<17,0>" and
"_DecimalT<16,0>".

However when I change it (put a plain conditional statement):

#include <stdlib.h>
#include <bcd.h>

int main (int argc, char *argv[])
{
  char Day1[7], Day2[7] ;
  _DecimalT<15, 0> v1, v2, v3, v4 ;

  memset (Day1, '0', 7) ;
  memset (Day2, '1', 7) ;

  v2 = __D("100") ;
  v3 = __D("10") ;
  v4 = __D("200") ;

  if (memcmp(Day1, Day2, 7) <= 0)
    v1 = v2 - v3 - v4 ;
  else
    v1 = v2 - v4 ;

  return(0) ;
}

Program compiles fine without errors...

In ILE/C both compile, of course....

What is the difference?

TIA,

Jevgeni.
-- 
This is the Bare Metal Programming IBM i (AS/400 and iSeries) (C400-L) mailing list
To post a message email: C400-L-Zwy7GipZuJhWk0Htik3J/[email protected]
To subscribe, unsubscribe, or change list options,
visit: http://lists.midrange.com/mailman/listinfo/c400-l
or email: C400-L-request-Zwy7GipZuJhWk0Htik3J/[email protected]
Before posting, please take a moment to review the archives
at http://archive.midrange.com/c400-l.
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.