Howdy, Stranger!

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

Categories

Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

"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

  • KenJacksonKenJackson Posts: 7Member
    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.