1

I wanted to write a program displaying all CPU options on a current CPU. Individual calls like this work:

if (__builtin_cpu_is("intel"))

Instead I would prefer to declare an array:

const char* cpuType[] = {
  "intel", "atom", "core2", "corei7", "nehalem",
  "westmere", "sandybridge", "amd", "amdfam10h", "barcelona", 
  "shanghai", "istanbul", "btver1", "amdfam15h",
  "bdver1", "bdver2", "bdver3", "bdver4", "btver2"
}

and in a loop check the same thing:

for (int i = 0; i < sizeof(cputype)/sizeof(char*); i++)
  if (__builtin_cpu_is(cpuType[i])

gcc refuses, saying it has to be a constant string.

Is there any way to make this work aside from writing the code over and over?

Dov
  • 8,000
  • 8
  • 46
  • 75

0 Answers0