bernard@boulder.colorado.edu (Bernie Bernstein) (11/17/90)
I don't know if this is common knowledge, but I found a bug in the Think C compiler concerning the ?: operator and structs. It doesn't accept the following program segment: .. typedef struct { long a; long b; } MY_TYPE; .. foo(short x) { MY_TYPE id1,id2,id3; id1 = x ? id2 : id3; /* Illegal operation on struct/union */ } This same program compiles fine using an if statement: if (x) then id1 = id2; else id1 = id3; Is there any fix for this? Am I doing something wrong? Should I just wait for the next version? I can live without this operator, but I like using it to build macros. This worked when MY_TYPE was a long instead of a struct. Bernie Bernstein bernard@boulder.colorado.edu BERNARDB@applelink.apple.com (303)492-8136
bernard@boulder.Colorado.EDU (Bernie Bernstein) (11/17/90)
I don't know if this is common knowledge, but I found a bug in the Think C compiler concerning the ?: operator and structs. It doesn't accept the following program segment: ... typedef struct { long a; long b; } MY_TYPE; ... foo(short x) { MY_TYPE id1,id2,id3; id1 = x ? id2 : id3; /* Illegal operation on struct/union */ } This same program compiles fine using an if statement: if (x) then id1 = id2; else id1 = id3; Is there any fix for this? Am I doing something wrong? Should I just wait for the next version? I can live without this operator, but I like using it to build macros. This worked when MY_TYPE was a long instead of a struct. -- o, ,, , | Bernie Bernstein | , ,, L>O/ \,/ \ ,| University of Colorado at boulder |/ \,,/ \ O./ ' / . `, / | office: (303) 492-8136 | / ` \ ,. ,/ / , ' | email: bernard@boulder.colorado.edu | / '' \
hairston@henry.ece.cmu.edu (David Hairston) (11/18/90)
[bernard@boulder.Colorado.EDU (Bernie Bernstein) writes:] [] I don't know if this is common knowledge, but I found a bug in the [] Think C compiler concerning the ?: operator and structs. It doesn't [] accept the following program segment: [] [] ... [] [] typedef struct { [] long a; [] long b; [] } MY_TYPE; [] [] ... [] [] foo(short x) [] { [] MY_TYPE id1,id2,id3; [] [] id1 = x ? id2 : id3; /* Illegal operation on struct/union */ my guess is that you've declared id1 to have allocated space and so you can't change it's address as implied above. i believe you want: MY_TYPE *id1, id2, id3; ... id1 = x ? &id2 : &id3; -dave- hairston@henry.ece.cmu.edu
d88-jwa@dront.nada.kth.se (Jon W{tte) (11/18/90)
In article <HAIRSTON.90Nov17132639@henry.ece.cmu.edu> hairston@henry.ece.cmu.edu (David Hairston) writes: >[bernard@boulder.Colorado.EDU (Bernie Bernstein) writes:] >[] typedef struct { >[] long a; >[] long b; >[] } MY_TYPE; >[] foo(short x) >[] { >[] MY_TYPE id1,id2,id3; >[] >[] id1 = x ? id2 : id3; /* Illegal operation on struct/union */ >my guess is that you've declared id1 to have allocated space and so >you can't change it's address as implied above. i believe you want: > MY_TYPE *id1, id2, id3; > id1 = x ? &id2 : &id3; Well, this is something else. You should be able to assign structs to each other. This should result in a bitwise copy. Like, id1 = id2 ; /* This is BlockMove ( id2 , id1 , sizeof ( id1 ) ) */ > -dave- >hairston@henry.ece.cmu.edu Now, you should know that Think C isn't ANSI C, porting that beast ;-) h+ h+@nada.kth.se "Moof!(tm)"
phils@chaos.cs.brandeis.edu (Phil Shapiro) (11/20/90)
In article <1990Nov18.103920.24295@nada.kth.se> d88-jwa@dront.nada.kth.se (Jon W{tte) writes: In article <HAIRSTON.90Nov17132639@henry.ece.cmu.edu> hairston@henry.ece.cmu.edu (David Hairston) writes: >[bernard@boulder.Colorado.EDU (Bernie Bernstein) writes:] >[] typedef struct { >[] long a; >[] long b; >[] } MY_TYPE; >[] foo(short x) >[] { >[] MY_TYPE id1,id2,id3; >[] >[] id1 = x ? id2 : id3; /* Illegal operation on struct/union */ >my guess is that you've declared id1 to have allocated space and so >you can't change it's address as implied above. i believe you want: > MY_TYPE *id1, id2, id3; > id1 = x ? &id2 : &id3; Well, this is something else. You should be able to assign structs to each other. This should result in a bitwise copy. Like, id1 = id2 ; /* This is BlockMove ( id2 , id1 , sizeof ( id1 ) ) */ > -dave- >hairston@henry.ece.cmu.edu Now, you should know that Think C isn't ANSI C, porting that beast ;-) This is considered by us (at Symantec) to be a bug. More specifically, it is an area where we are non-ANSI compiliant. While the current version does not claim to be fully compliant, the next major release will be, and the above code (using ?) will work. Currently structures can be used in assignment or in function return. BTW, id1 = *( x ? &id2 : &id3); works (if you don't mind REAL ugly code :-) -phil -- Phil Shapiro Technical Support Analyst Language Products Group Symantec Corporation Internet: phils@chaos.cs.brandeis.edu
Chris.Gehlker@p12.f56.n114.z1.fidonet.org (Chris Gehlker) (11/22/90)
hairston@henry.ece.cmu.edu (David Hairston) writes: > [bernard@boulder.Colorado.EDU (Bernie Bernstein) writes:] > [] I don't know if this is common knowledge, but I found a bug in the > [] Think C compiler concerning the ?: operator and structs. It doesn't > [] accept the following program segment: > [] > [] ... > [] > [] typedef struct { > [] long a; > [] long b; > [] } MY_TYPE; > [] > [] ... > [] > [] foo(short x) > [] { > [] MY_TYPE id1,id2,id3; > [] > [] id1 = x ? id2 : id3; /* Illegal operation on struct/union */ > > my guess is that you've declared id1 to have allocated space and so > you can't change it's address as implied above. i believe you want: > > MY_TYPE *id1, id2, id3; > ... > id1 = x ? &id2 : &id3; I guess he wants id1 == x ? &id2 : &id3; ^^ -- Uucp: ...{gatech,ames,rutgers}!ncar!asuvax!stjhmc!56.12!Chris.Gehlker Internet: Chris.Gehlker@p12.f56.n114.z1.fidonet.org