[cmake-developers] Questions about coding conventions

Daniel Pfeifer daniel at pfeifer-mail.de
Mon Jun 13 10:14:51 EDT 2016


On Mon, Jun 13, 2016 at 2:09 PM, Ben Boeckel <ben.boeckel at kitware.com> wrote:
> On Mon, Jun 13, 2016 at 00:03:29 +0200, Daniel Pfeifer wrote:
>> Can you show an example? To be clear: We are looking for a function,
>> that has a code path for `str == NULL` and a *different* codepath for
>> `str[0] = '\0'`.
>
> As input to functions?

Either input or output. I am interested about both cases.

> Usually NULL means "unset". See properties,
> variable values, etc. As an output, any place which doesn't care should
> already be using GetSafeDefinition().

I know that, at the moment, NULL is used for "unset" in many places. I
am trying to figure out whether we could theoretically use "empy" to
mean "unset".
If there is a case where we distinguish between null and empty, this
will not be possible.

> As a concrete example, `set(CACHE)` cares about NULL versus *s == NULL:

Thanks for the example. I found the check for `s != NULL` in the
second line. Can you help me finding the check for `*s == NULL`?

>     const char* existingValue = state->GetCacheEntryValue(variable);
>     if (existingValue &&
>         (state->GetCacheEntryType(variable) != cmState::UNINITIALIZED)) {
>       // if the set is trying to CACHE the value but the value
>       // is already in the cache and the type is not internal
>       // then leave now without setting any definitions in the cache
>       // or the makefile
>       if (cache && type != cmState::INTERNAL && !force) {
>         return true;
>       }
>     }
>
>     // if it is meant to be in the cache then define it in the cache
>     if (cache) {
>       this->Makefile->AddCacheDefinition(variable, value.c_str(), docstring,
>                                          type, force);
>     } else {
>       // add the definition
>       this->Makefile->AddDefinition(variable, value.c_str());
>     }


More information about the cmake-developers mailing list