-->
Page 1 of 1

What does the 'LOCAL' mean when defining a variable ?

PostPosted: Wed May 02, 2018 4:46 am
by jj8431
Hi I noticed in many demo programs there's a 'LOCAL' key word in front of a variable definition, What does it mean and how/when to use it?
Any reply will be appreciated.

Re: What does the 'LOCAL' mean when defining a variable ?

PostPosted: Thu May 03, 2018 10:44 pm
by jcmvbkbc
jj8431 wrote:there's a 'LOCAL' key word in front of a variable definition, What does it mean and how/when to use it?

It's a macro defined in the SDK:
Code: Select all$ grep -rw LOCAL | grep define
ESP8266_NONOS_SDK_V2.0.0_16_08_10/include/c_types.h:#define LOCAL       static
ESP8266_NONOS_SDK_V2.0.0_16_08_10/include/c_types.h.orig:#define LOCAL       static
xtensa-lx106-elf/xtensa-lx106-elf/sysroot/usr/include/c_types.h:#define LOCAL       static
xtensa-lx106-elf/xtensa-lx106-elf/sysroot/usr/include/c_types.h.orig:#define LOCAL       static
esp_iot_sdk_v1.5.2/include/c_types.h:#define LOCAL       static
esp_iot_sdk_v1.5.2/include/c_types.h.orig:#define LOCAL       static

There's no reason to use it instead of using 'static' keyword directly.

Re: What does the 'LOCAL' mean when defining a variable ?

PostPosted: Fri May 04, 2018 12:49 am
by McChubby007
Redefining a C++ keyword is not recommended IMHO and it just leads to confusion/readability as is exemplified here.
Static at module (file) scope means it is a global variable only within usable scope of the module/file it is defined within. It is the C way of making variables semi-private but shareable within a set of functions (very loosely like class variables in C++). The variables are hidden from other modules/files, and cannot be accessed via an extern keyword; they also allow the compiler more chance to make optimisations.