   Pointer Validation
  Is there any safe way to write a macro that can vallidate a pointer or would function templates be the way to go? I am asking because I am sick and tired of using the if statement over and over again simply to see if a pointer is null. If someone knows of a cleaner more efficient technique, I would love to hear it. Thank you.[edited by - kelaklub on December 8, 2003 12:23:06 PM]
  Use ASSERT(); ;  Well, if you use smart pointers (eg the ones boost provides) then you can be sure that if the pointer is in scope, it points to a valid object. The smart pointers in boost also give some very nice shared ownership semantics, so you don''t have to worry when passing them around either. ;  Could you give me an example with assert, I have never heard of that. Thanks. ;  What''s so tiring about it?if (pointer) {    ...}else {    ...} ;  Nothing tiring really just wondered if that is the best way to go about it or would writing a procedure that does the same thing be better. Just curious as to what other people were doing? ;  The problem is that whether you do a procedure or macro or whatever, you still need to test the result to determine what to do if the pointer is NULL. If you want to do the same thing everytime a pointer is NULL, like throw an exception or something, then a macro or function would work, but otherwise, you''re going to need the if/else logic. ;  You could just not use pointers. ;  Well, we do need pointers every now and then, but I agree with fizban75. If there is a general way to do this it would have been implemented into c probably a long time ago. Thanks for the feedback. ;  Use references, they''re guaranteed by the language to reference a valid object. 