digitalmars.D.learn - [std.c.stdlib] (malloc(something) is null) or (malloc(something)
- Alexandr Druzhinin (11/11) May 20 2014 In D code I do
- bearophile (5/16) May 20 2014 "x is null" or "x == null" are the same operation when x is a raw
- Adam D. Ruppe (4/5) May 20 2014 Both would work and do the same thing, but I prefer "is null"
- bearophile (5/8) May 20 2014 Curiously I do the opposite, I use == to remind me it's a pointer
In D code I do void* data = GC.malloc(...); if(data is null) ... In C code I do void* data = malloc(...); if(data == null) ... What to do when in D code I have void* data = std.c.stdlib.malloc(...); if(data ?) // is null vs == 0
May 20 2014
Alexandr Druzhinin:In D code I do void* data = GC.malloc(...); if(data is null) ... In C code I do void* data = malloc(...); if(data == null) ... What to do when in D code I have void* data = std.c.stdlib.malloc(...); if(data ?) // is null vs == 0"x is null" or "x == null" are the same operation when x is a raw pointer. Bye, bearophile
May 20 2014
On Tuesday, 20 May 2014 at 14:03:17 UTC, Alexandr Druzhinin wrote:if(data ?) // is null vs == 0Both would work and do the same thing, but I prefer "is null" because that is most consistent with other D code (where there might be a difference between the two).
May 20 2014
Adam D. Ruppe:but I prefer "is null" because that is most consistent with other D code (where there might be a difference between the two).Curiously I do the opposite, I use == to remind me it's a pointer :-) Bye, bearophile
May 20 2014