Constant local variable in c

Are constant variables used? I could not find much information about them on the Internet or in the index of my textbook C - Art and Science C.

Anything you can report on them, especially their announcement and example announcement , would be helpful. I assume to declare them that you use "persistent" as a keyword?

static void foo( void ) {
  persistent unsigned int width = 5;
}

This is the only useful link I could find: "Constant variables retain their state when the board is turned off and on, when main is started, and when the system is reset. Persistent variables lose their state when the code is loaded as a result of file upload or download." http://www.newtonlabs.com/ic/ic_5.html#SEC9

thank!

+3
source share
3 answers

The keyword you want is staticin a local (not global) context.

The meaning of the context is important:

#include <stdio.h>

static int foo;

int main(int argc, char **argv){
  //...
}

Here static, it means that it foohas a file area (i.e. not extern).

While

char *strtok(char *str, char *sep){
  static char *last;
  //...
}

lastsaved between calls strtok.

All that has been said, they are rarely used, because they are rarely useful and completely unacceptable in a multi-threaded context (where they are waiting for the race condition).

+3
source

Interactive C (, ) persistent, C. , , " , , main, reset".

persistent Interactive C , Motorola, .

Interactive C - C Motorola 6811 . MIT LEGO Robot Design (6.270), Interactive C . Interactive C - : , , . IC 6.270, HandyBoard RugWarrior RugWarrior Pro. .

(, ), static.

+8

jkerian, , ... C ( ), , , - EEPROM.

, , , . FRAM. FRAM RAM whitch - , . : CCS COFF 0 ( ) .

0

Source: https://habr.com/ru/post/1778560/


All Articles