# Disallow numbers as variable names

**URL:** <https://discourse.cmake.org/t/disallow-numbers-as-variable-names/9354>\
**Category:** Code\
**Created:** [November 3, 2023, 2:10pm UTC](https://discourse.cmake.org/t/disallow-numbers-as-variable-names/9354 "2023-11-03T14:10:11Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![trmagma](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/t/74df32/32.png) [@trmagma](https://discourse.cmake.org/u/trmagma)\
**Post date:** [November 3, 2023, 2:10pm UTC](https://discourse.cmake.org/t/disallow-numbers-as-variable-names/9354/1 "2023-11-03T14:10:11Z")

</div>

I found a strange behavior:  
if ( value EQUAL 0 )  
did not match even if value has the value 0. The cause was, that it seems that there was a variable ${0} which had a value different from 0. The following example demonstrates the behavior:

set ( 0 4 ) # yes it is the digit 0 which is set to 4. In production code this variable came from somewhere else.

set ( value 0 )  
if ( value EQUAL 0 ) # evaluated to false  
message (“value is equal to 0: ${value}” )  
else()  
message ( “value is NOT equal to 0: ${value}” )  
endif()  
if ( value EQUAL “0” ) # evaluated to true  
message (“value is equal to 0: ${value}” )  
else()  
message ( “value is NOT equal to 0: ${value}” )  
endif()

A workaround is using the style of the second if-statement using quotes around the critical variable. I dont know where ${0} is set (might be a bug in our code, might be some something set by CMake). We have a lot of code of the first style and it seems to work fine, I fear a ticking bomb, when someone (or some bug) says, that 0 is not 0 any longer, together with the implicit evaluation of the if-statement.

**My suggestion** : Disallow variable names starting with digits (as most languages do), or at least disallow variable names only consisting of digits. Make a policy to use the old/current behavior.

Similar problem:

> [@if(... EQUAL 0) syntax](https://discourse.cmake.org/t/if-equal-0-syntax/3886):
>
> I believed correct syntax for the if(EQUAL) would be like try\_run(runcode buildOK ...) if(runcode EQUAL 0) endif() That usually works, but I ran into a CentOS 8 system where even though message(STATUS ${runcode}) showed 0, the if(runcode EQUAL 0) clause failed to be true. The system locale is English US. The statement does work on other systems. On the problem system, the try\_run() code does run correctly and gives expected RUN\_OUTPUT\_VARIABLE value as per my code (say hello.c). To work ar…

---

<div class="post-metadata">

**Author:** ![ben.boeckel](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/b/ea5d25/32.png) [@ben.boeckel](https://discourse.cmake.org/u/ben.boeckel)\
**Post date:** [November 3, 2023, 3:39pm UTC](https://discourse.cmake.org/t/disallow-numbers-as-variable-names/9354/2 "2023-11-03T15:39:41Z")

</div>

Please see this issue: [https://gitlab.kitware.com/cmake/cmake/-/issues/23954](https://gitlab.kitware.com/cmake/cmake/-/issues/23954)
