Checking C return results against NULL
Rikki Cattermole via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Wed Dec 31 03:29:18 PST 2014
On 1/01/2015 12:22 a.m., Laeeth Isharc wrote:
> Am I missing a more agreeable way to check the return value of a C
> function against NULL. It's fine if it's a char*, but if it returns a
> pointer to some kind of struct, one has to go through and convert each
> instance of NULL to a cast of the appropriate return type. Eg
> cast(funnystruct*)0
>
> if ((tomime_fields.fld_description==cast(char*)0))
> throw new Exception("show_part_info: description is NULL");
== for value
is for pointers
if (tomime_fields.fld_description is null)
throw new Exception("...");
More information about the Digitalmars-d-learn
mailing list