Re: init
bob@xxxxxxxxxxxxxx wrote:
why won't this work?
float boxcenter[3];
if (nodectr == 0)
boxcenter = {centerpt[0] + halfwidth/2.0, centerpt[1] + halfwidth/2.0,
centerpt[2] + halfwidth/2.0};
Because C doesn't do array assignments. You can, however, do a
declaration with initialization upon entering a block:
{
float boxcenter[3] = {centerpt[0] + halfwidth/2.0,
centerpt[1] + halfwidth/2.0,
centerpt[2] + halfwidth/2.0};
assuming that enterpt and halfwidth are defined on entry.
--
Thad
.
Relevant Pages
- Re: stuck with file organisation and global a global array of strings
... the .h file is included from various .c files and when i compile i get ... It's a declaration. ... It's also and a definition and a default initialization, ... this is actually an objective-c project and when i say ".c" above i'm ... (comp.lang.c) - Re: Initialization is done before the program starts executing ?
... initialization is done once only, ... why the declaration is executed but the initialization is not? ... These two concepts are scope and execution flow. ... (comp.lang.c) - Re: char * ptr = "hello" and char carray[] = "hello"
... Is it a fair statement that char *ptr will take ... the first declaration creates a string ... are initialized with character string literals. ... section 4.9 Initialization, ... (comp.lang.c) - Re: History of French
... >Good programmers put them up at the top, ... >declaration when you need it. ... After the first time, it's *not* initialization, it's assignment. ... Richard Herring ... (sci.lang) - Re: Question on switch block scope
... >> Is this not a declaration with initialization, ... there is no such declaration for ... >out myself (it only requires one extra typing of the variable ... Dan Pop ... (comp.lang.c) |
|