Reputation: 117
I am converting a code written in C to Pascal. I got doubt in a part that seems to be simple but generated a doubt!
int Length = ...;
void *FileBase = ...;
if (Length && FileBase != NULL)
....
The above line with the condition "if", it means "Length" and "Filebase" are respectively different from "0" and "Null"?
it is the same as if (Length <> 0) and (FileBase <> Nil) then ???
Upvotes: 0
Views: 1701
Reputation: 14160
You are right – it should be translated as if (Length <> 0) and (FileBase <> nil)
.
Upvotes: 1
Reputation: 613572
This is not really a Delphi or Pascal question. It's a question about operator precedence in C. There are many references that will tell you about that. For example: http://en.cppreference.com/w/c/language/operator_precedence.
The key point is that !=
has higher precedence than &&
. So the expression
Length && FileBase != NULL
has the same meaning as
Length && (FileBase != NULL)
Since in C values are regarded as true if they are non-zero, in Delphi/Pascal this expression would be:
(Length <> 0) and (FileBase <> nil)
Upvotes: 2