Gamestudio Links
Zorro Links
Newest Posts
Purchase A8 full licence version
by ukgamer. 04/29/26 18:09
Z9 getting Error 058
by k_ivan. 04/25/26 19:13
ZorroGPT
by TipmyPip. 04/25/26 16:09
Stooq now requires an API key
by jcl. 04/13/26 09:42
Strange "Alien" Skull created with >Knubber<
by NeoDumont. 04/10/26 18:58
AUM Magazine
Latest Screens
Dorifto samurai
Shadow 2
Rocker`s Revenge
Stug 3 Stormartillery
Who's Online Now
0 registered members (), 4,296 guests, and 26 spiders.
Key: Admin, Global Mod, Mod
Newest Members
ukgamer, valino, juergenwue, VladMak, Geir
19210 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
P_ANDAND:LONG:POINTER:LONG #182156
02/05/08 04:11
02/05/08 04:11
Joined: May 2002
Posts: 7,441
ventilator Offline OP
Senior Expert
ventilator  Offline OP
Senior Expert

Joined: May 2002
Posts: 7,441
if(you.type == NULL && entity1 && entity2 && my.state == 1)

causes this error:
can not translate P_ANDAND:LONG:POINTER:LONG

this way it works:
if(you.type == NULL && (long)entity1 && (long)entity2 && my.state == 1)

can this be fixed?

Re: P_ANDAND:LONG:POINTER:LONG [Re: ventilator] #182157
02/05/08 16:29
02/05/08 16:29
Joined: Jul 2000
Posts: 28,094
Frankfurt
jcl Offline

Chief Engineer
jcl  Offline

Chief Engineer

Joined: Jul 2000
Posts: 28,094
Frankfurt
Yes. '&&' is a boolean operation that requires boolean expressions. A boolean expression is something that's either zero or nonzero. "entity" is a pointer and not a boolean expression.

Re: P_ANDAND:LONG:POINTER:LONG [Re: jcl] #182158
02/05/08 16:38
02/05/08 16:38
Joined: Jan 2006
Posts: 1,829
Neustadt, Germany
T
TWO Offline

Serious User
TWO  Offline

Serious User
T

Joined: Jan 2006
Posts: 1,829
Neustadt, Germany
Correct me if I'm wrong, but a pointer == 0 is true and pointer != 0 is false in C, so this is valid syntax.

btw the compiler errors are kinda cryptic, this could be improved.

Re: P_ANDAND:LONG:POINTER:LONG [Re: TWO] #182159
02/05/08 23:36
02/05/08 23:36
Joined: May 2002
Posts: 7,441
ventilator Offline OP
Senior Expert
ventilator  Offline OP
Senior Expert

Joined: May 2002
Posts: 7,441
i also thought in c you can use pointers in if clauses like that and i agree that lite-c error messages could be better.

Re: P_ANDAND:LONG:POINTER:LONG [Re: TWO] #182160
02/06/08 00:09
02/06/08 00:09
Joined: Jul 2000
Posts: 8,973
Bay Area
Doug Offline
Senior Expert
Doug  Offline
Senior Expert

Joined: Jul 2000
Posts: 8,973
Bay Area
Quote:

Correct me if I'm wrong, but a pointer == 0 is true and pointer != 0 is false in C, so this is valid syntax.




Yes, but this part:

Code:

(..&& entity1 && entity2...)



is not correct. It will work in most version of ANSI C and C++, but most programmers will recommended against it.

You should do something like:

Code:

(..&& (entity1 != NULL) && (entity2 != NULL) ..)




Conitec's Free Resources:
User Magazine || Docs and Tutorials || WIKI
Re: P_ANDAND:LONG:POINTER:LONG [Re: Doug] #182161
02/06/08 00:28
02/06/08 00:28
Joined: May 2002
Posts: 7,441
ventilator Offline OP
Senior Expert
ventilator  Offline OP
Senior Expert

Joined: May 2002
Posts: 7,441
why would most programmers recommend against it? what problems can it cause?

if(entity1) // but if you only use a single pointer and no && it is ok?

Re: P_ANDAND:LONG:POINTER:LONG [Re: ventilator] #182162
02/06/08 01:27
02/06/08 01:27
Joined: Jul 2000
Posts: 8,973
Bay Area
Doug Offline
Senior Expert
Doug  Offline
Senior Expert

Joined: Jul 2000
Posts: 8,973
Bay Area
I probably overstated myself. Most C programmers are probably perfectly okay with it. But C programmers are crazy and enjoy hunting down memory leaks and memorizing which operator has a higher precedence.

IMHO, sane programmers try to avoid this.

In the example above, you are assuming that the compiler will automatically cast your pointer into a boolean value. Automatic casting doesn't always work the way you think it will.

This isn't an issue with most C compilers because it is a common practice to cast pointers to int, but it is still a cast.


Conitec's Free Resources:
User Magazine || Docs and Tutorials || WIKI

Moderated by  HeelX, Lukas, rayp, Rei_Ayanami, Superku, Tobias, TWO, VeT 

Gamestudio download | Zorro platform | shop | Data Protection Policy

oP group Germany GmbH | Birkenstr. 25-27 | 63549 Ronneburg / Germany | info (at) opgroup.de

Powered by UBB.threads™ PHP Forum Software 7.7.1