"object of variable size may not be initialized" ?



here you see following listing in C :

#include
#include
#include

#define addr 4194304

/* for-loop mit addr adresses */
int main(void)
{

int i;
int x;

for( i = 0; i<addr; i++ )
{
int x[i]=true;
if (i==addr)
break;else
continue; /* here should be a pointer with the aim for each address number to be set as true: int x[i]=true; */

}
return (0);
}

----------------------------------

yes, when I want to compile this, the error report of gcc in line 16 is:
"object of variable size may not be initialized"
it is probably not allowed to set an increasing index like i in x[i] as true.
means that then a pointer is necessary ...

how would be the solution for this ? I want that each counting step of i is set as true. Means each address should be set as true.

This programm would perform a platform-independent chip-update e.g. in bios on each mainboard.
No matter which manufactor and no matter which bios-chip.

I ask here, because I had the solution in 2005, but the solution got lost
because of new installation.

tuvm for reply.
cheers.
dschinn

Comments

  • Are you trying to write 4 million int-size 'true' values?
    Probably not.
    But I can't tell what the goal really is.

    This line declares a single variable that's never initialized or used:
    [b]int x;[/b]

    This line attempts to declare an array of size [b]i[/b], which is a variable (which isn't allowed in C), and initialize the whole array to a single value:
    [b]int x[i]=true;[/b]

    If the goal is to write a single value to a single address, you might do it like this:
    [b]unsigned char *p = (unsigned char *)addr;
    *p = 1;[/b]

    And there's no need to break or continue--that's what the for-loop does.
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

In this Discussion