osmo-pcu[master]: RFC: remove this == NULL checks

This is merely a historical archive of years 2008-2021, before the migration to mailman3.

A maintained and still updated list archive can be found at https://lists.osmocom.org/hyperkitty/list/OpenBSC@lists.osmocom.org/.

Neels Hofmeyr gerrit-no-reply at lists.osmocom.org
Wed Jun 1 10:30:34 UTC 2016


Patch Set 1: Code-Review-1

Here's my guess:

If a class has no virtual functions, the functions are essentially static and merely get passed the 'this' pointer of the instance called upon.

For an inline foo() const function, the compiler is instructed to insert the code in-place, nevermind it being a class member namespace wise.

The actual value of 'this' happens during runtime. The compiler can try hard to avoid NULL there, but it's easy to achieve at runtime.

MyClass *instance = NULL;
instance->my_non_virtual_function();

In this code, the NULL 'this' is actually passed into the function body.

(For a virtual function, the program would first try to look up the function pointer in the virtual function table, which would probably result in a segfault.)

Plus: Jacob wrote it. My opinion of Jacob's compiler knowledge is highly esteemed. Let's ask him first. Plus: Coverity warned about one of those.

On the counter argument, the compiler does complain about comparison of 'this' against NULL. However, I trust that Jacob had his reasons in these particular instances. Would be nice to get rid of the warning though.

Giving -1 but it's more like a -0 until we have more precise knowledge.

-- 
To view, visit https://gerrit.osmocom.org/136
To unsubscribe, visit https://gerrit.osmocom.org/settings

Gerrit-MessageType: comment
Gerrit-Change-Id: Ifddaef70bb0a4402050c817b1000d515c3a7118b
Gerrit-PatchSet: 1
Gerrit-Project: osmo-pcu
Gerrit-Branch: master
Gerrit-Owner: lynxis lazus <lynxis at fe80.eu>
Gerrit-Reviewer: Harald Welte <laforge at gnumonks.org>
Gerrit-Reviewer: Jenkins Builder
Gerrit-Reviewer: Neels Hofmeyr <nhofmeyr at sysmocom.de>
Gerrit-HasComments: No



More information about the OpenBSC mailing list