initialize array based on condition.
I want to declare an array based on the condition (board type). I get the board type as return value from a function. Have written the snippet of the code from my project below.
Code:
#include <stdio.h>
#define F120 1
#define F120EX 2
int getPlatformType();
int main()
{
int platformType;
platformType = getPlatformType();
if (platformType == F120) {
const char *portList[] = {"eth0", "eth1" };
} else if (platformType == F120EX ) {
const char *portList[] = {"eth0", "eth1", "eth3", "eth4"};
}
int portsize = sizeof(portList) / sizeof(portList[0]);
// other code follows..
return 0;
}
/* Test purpose only */
int getPlatformType()
{
return F120;
}
I am getting the following compilation error :
g++ portdefine.cpp
portdefine.cpp: In function 'int main()':
portdefine.cpp:23: error: 'portList' was not declared in this scope[/B]
Please let me know the correct method