Hello,

Is a fundamental data type with the const qualifier within a function scope initialized at run-time?

I think that it is clearly specified for C++ and that there is, indeed, a run-time initialization of such a variable. However, is this also the case for plain ANSI C?

See the example below written in old-fashioned pure ANSI C. Is n_rand initialized at run-time? Is this specified in the ANSI/ISO specification or is it a language extension? I can not find any mention of this language usage in the ANSI C specification.

Thanks a lot for any help clarifying this issue.
Chris.

Code:
#include <stdlib.h>
#include <stdio.h>

static const int rand100(void)
{
  // Return a random integer ranging from 0...99
  return (int) ((100.0 * (double) rand()) / RAND_MAX);
}

int main(int argc, char* argv[])
{
  int i;
  for(i = 0; i < 100; i++)
  {
    // Is this a run-time initialization?
    const int n_rand = rand100();

    fprintf(stdout, "%i\n", n_rand);
  }
  return 1;
}