When do I use "__attribute__((nonnull))" vs "not_null T* "?

I'm accustomed to using __attribute__((nonnull)) when expressing pointers that should not be null.

void f(int* ptr __attribute__((nonnull)));  int main(){     int* ptr = new int(1);     f(ptr); } void f(int* ptr){/*impl*/} 

However, with the GSL, there is also the not_null<T*> wrapper type.
void function1(gsl::not_null n);

void f(gsl::not_null<int*> n);  int main(){     int* ptr = new int(1);     f(ptr); } void f(gsl::not_null<int*> n){/*impl*/} 

Assuming the language facilities are there to support the GSL version, should I always be using not_null<T*> in place of __attribute__((nonnull)) now?

I've been under the impression that the compiler attribute may aid in optimizations, but the wrapper version resolves down to an unattributed pointer.

Replay

Category: c# Time: 2016-07-28 Views: 0

Related post

iOS development

Android development

Python development

JAVA development

Development language

PHP development

Ruby development

search

Front-end development

Database

development tools

Open Platform

Javascript development

.NET development

cloud computing

server

Copyright (C) avrocks.com, All Rights Reserved.

processed in 0.287 (s). 12 q(s)