diff --git a/miosix/_tools/testsuite/testsuite.cpp b/miosix/_tools/testsuite/testsuite.cpp index 5d2b330327842f637876c18e6765a79bb4846e52..bb7cf7a450f67c5c0e25d6daf17863e7bf122f7b 100644 --- a/miosix/_tools/testsuite/testsuite.cpp +++ b/miosix/_tools/testsuite/testsuite.cpp @@ -3695,7 +3695,7 @@ static void test_24() dtorCalled=false; { intrusive_ref_ptr<Base0> ptr1; - assert(ptr1==0); + assert(!ptr1); } assert(dtorCalled==false); @@ -3814,7 +3814,7 @@ static void test_24() { intrusive_ref_ptr<Derived1> ptr2= dynamic_pointer_cast<Derived1>(ptr1); - assert(ptr2==0); + assert(!ptr2); } assert(dtorCalled==false); } @@ -3844,7 +3844,7 @@ static void test_24() intrusive_ref_ptr<Base0> ptr1(new Base0); ptr1.reset(); assert(dtorCalled); - assert(ptr1==0); + assert(!ptr1); } // Reset, on a shared pointer @@ -3854,8 +3854,8 @@ static void test_24() { intrusive_ref_ptr<Base0> ptr2(ptr1); ptr1.reset(); - assert(ptr1==0); - assert(ptr2!=0); + assert(!ptr1); + assert(ptr2); ptr2->check(); } assert(dtorCalled); diff --git a/miosix/e20/callback.h b/miosix/e20/callback.h index 9d24583bc454a11def47c6f5770df884dc474265..5f3df322beecdee293e303e11a6d30772766ffe8 100644 --- a/miosix/e20/callback.h +++ b/miosix/e20/callback.h @@ -1,5 +1,5 @@ /*************************************************************************** - * Copyright (C) 2012, 2013, 2014, 2105, 2106 by Terraneo Federico * + * Copyright (C) 2012-2023 by Terraneo Federico * * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * @@ -25,8 +25,7 @@ * along with this program; if not, see <http://www.gnu.org/licenses/> * ***************************************************************************/ -#ifndef CALLBACK_H -#define CALLBACK_H +#pragma once #include <stdint.h> @@ -115,14 +114,14 @@ public: /** * Default constructor. Produces an empty callback. */ - Callback() : operation(0) {} + Callback() : operation(nullptr) {} /** * Constructor. Not explicit by design. * \param functor function object a copy of which is stored internally */ template<typename T> - Callback(T functor) : operation(0) + Callback(T functor) : operation(nullptr) { *this=functor; } @@ -156,8 +155,8 @@ public: */ void clear() { - if(operation) operation(any,0,DESTROY); - operation=0; + if(operation) operation(any,nullptr,DESTROY); + operation=nullptr; } /** @@ -165,7 +164,7 @@ public: */ void operator() () { - if(operation) operation(any,0,CALL); + if(operation) operation(any,nullptr,CALL); } /** @@ -173,7 +172,7 @@ public: */ void call() { - operation(any,0,CALL); + operation(any,nullptr,CALL); } /** @@ -189,7 +188,7 @@ public: */ ~Callback() { - if(operation) operation(any,0,DESTROY); + if(operation) operation(any,nullptr,DESTROY); } private: @@ -210,7 +209,7 @@ template<unsigned N> Callback<N>& Callback<N>::operator= (const Callback<N>& rhs) { if(this==&rhs) return *this; //Handle assignmento to self - if(operation) operation(any,0,DESTROY); + if(operation) operation(any,nullptr,DESTROY); operation=rhs.operation; if(operation) operation(any,rhs.any,ASSIGN); return *this; @@ -227,7 +226,7 @@ Callback<N>& Callback<N>::operator= (T functor) //This should not fail unless something has a stricter alignment than double static_assert(__alignof__(any)>=__alignof__(T),""); - if(operation) operation(any,0,DESTROY); + if(operation) operation(any,nullptr,DESTROY); new (reinterpret_cast<T*>(any)) T(functor); operation=TypeDependentOperation<T>::operation; @@ -235,5 +234,3 @@ Callback<N>& Callback<N>::operator= (T functor) } } //namespace miosix - -#endif //CALLBACK_H diff --git a/miosix/filesystem/file_access.cpp b/miosix/filesystem/file_access.cpp index 74d8e5a6a5b917ea1be16137e6c4665a074b8a3d..daf83484953131997f33637a1869da1ff1f52604 100644 --- a/miosix/filesystem/file_access.cpp +++ b/miosix/filesystem/file_access.cpp @@ -507,7 +507,7 @@ FilesystemManager& FilesystemManager::instance() int FilesystemManager::kmount(const char* path, intrusive_ref_ptr<FilesystemBase> fs) { - if(path==0 || path[0]=='\0' || fs==0) return -EFAULT; + if(path==0 || path[0]=='\0' || !fs) return -EFAULT; Lock<FastMutex> l(mutex); size_t len=strlen(path); if(len>PATH_MAX) return -ENAMETOOLONG; diff --git a/miosix/kernel/intrusive.h b/miosix/kernel/intrusive.h index aac4476e7966cdc224c360c9ad8d661f91afc6b0..1fa4273a46a230d7ab74f243681fa55947603d34 100755 --- a/miosix/kernel/intrusive.h +++ b/miosix/kernel/intrusive.h @@ -183,7 +183,7 @@ public: /** * Default constructor */ - intrusive_ref_ptr() : object(0) {} + intrusive_ref_ptr() : object(nullptr) {} /** * Constructor, with raw pointer @@ -292,9 +292,9 @@ public: void reset() { if(decrementRefCount()) delete object; - // Object needs to be set to 0 regardless + // Object needs to be set to nullptr regardless // of whether the object is deleted - object=0; + object=nullptr; } /** @@ -347,7 +347,7 @@ private: */ bool decrementRefCount() { - if(object==0) return false; + if(object==nullptr) return false; return atomicAddExchange(&object->intrusive.referenceCount,-1)==1; } @@ -393,7 +393,7 @@ intrusive_ref_ptr<T>& intrusive_ref_ptr<T>::operator= (T* o) template<typename T> intrusive_ref_ptr<T> intrusive_ref_ptr<T>::atomic_load() const { - intrusive_ref_ptr<T> result; // This gets initialized with 0 + intrusive_ref_ptr<T> result; // This gets initialized with nullptr // According to the C++ standard, this causes undefined behaviour if // T has virtual functions, but GCC (and clang) have an implementation @@ -440,7 +440,7 @@ intrusive_ref_ptr<T> intrusive_ref_ptr<T>::atomic_exchange( volatile int *objectAddrInt=reinterpret_cast<volatile int*>(&object); temp=reinterpret_cast<T*>(atomicSwap(objectAddrInt,tempInt)); - intrusive_ref_ptr<T> result; // This gets initialized with 0 + intrusive_ref_ptr<T> result; // This gets initialized with nullptr // This does not increment referenceCount, as the pointer was swapped result.object=temp; return result; @@ -593,7 +593,7 @@ intrusive_ref_ptr<T> const_pointer_cast(const intrusive_ref_ptr<U>& r) template<typename T> intrusive_ref_ptr<T> atomic_load(const intrusive_ref_ptr<T> *p) { - if(p==0) return intrusive_ref_ptr<T>(); + if(p==nullptr) return intrusive_ref_ptr<T>(); return p->atomic_load(); } @@ -628,7 +628,7 @@ template<typename T> intrusive_ref_ptr<T> atomic_exchange(intrusive_ref_ptr<T> *p, intrusive_ref_ptr<T> r) { - if(p==0) return intrusive_ref_ptr<T>(); + if(p==nullptr) return intrusive_ref_ptr<T>(); return p->atomic_exchange(r); }