A
arnuld
Here is the program and i have some observations about the use of Static
storage class specifier. Please tell me whether I am right or wrong:
#include <stdio.h>
#define DBLVAL 1.001
int main(void)
{
int i = 0;
char c = 'c';
static char ch;
static int x = i;
static double d = DBLVAL;
ch = c;
printf("static int x = %d\n", x);
printf("static char ch = %c\n", ch);
printf("static doubler d = %f\n", d);
return 0;
}
==================== OUTPUT =========================
[arnuld@dune programs]$ gcc -ansi -pedantic -Wall -Wextra static.c
static.c: In function ‘main’:
static.c:14: error: initializer element is not constant
[arnuld@dune programs]$
OBSERVATION 1: If you going to initialize a variable declared with static
specifier then you can only pass compile-time constant values, else you
can't compile the program.
OBSERVATION 2: If you want to pass a variable (which is not a compile-
time constant) to a variable declared/defined with static specifier then
you can do that only in assignment.
storage class specifier. Please tell me whether I am right or wrong:
#include <stdio.h>
#define DBLVAL 1.001
int main(void)
{
int i = 0;
char c = 'c';
static char ch;
static int x = i;
static double d = DBLVAL;
ch = c;
printf("static int x = %d\n", x);
printf("static char ch = %c\n", ch);
printf("static doubler d = %f\n", d);
return 0;
}
==================== OUTPUT =========================
[arnuld@dune programs]$ gcc -ansi -pedantic -Wall -Wextra static.c
static.c: In function ‘main’:
static.c:14: error: initializer element is not constant
[arnuld@dune programs]$
OBSERVATION 1: If you going to initialize a variable declared with static
specifier then you can only pass compile-time constant values, else you
can't compile the program.
OBSERVATION 2: If you want to pass a variable (which is not a compile-
time constant) to a variable declared/defined with static specifier then
you can do that only in assignment.