Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>After looking at the answers and comments, I think there are a few more things to clarify:</p> <ol> <li>If variables are defined / declared outside any function body in a compilation unit, you must specify the storage class , e.g. <code>static</code></li> <li>These variables will be put to BSS section of you executable file. And you'd better initialize then.</li> <li>When defining an array, you could use initializer <code>{...}</code> to initialize it. But you cannot use it in assignment statement.</li> <li><code>double rob_leftcolor[3] = {1.0, 0.0, 0.0}</code> is a definition, while <code>rob_leftcolor[3] = {1.0, 0.0, 0.0}</code> is an assignment, so you can not use initializer here.</li> <li>Please make sure you know the differences between declaration and definition in C.</li> </ol> <p>For storage class, consider the case below, without <code>static</code>, you are actually defining global variables:</p> <pre><code>// a1.c static double rob_size, rob_tilt; rob_leftcolor [3] = {1.0, 0.0, 0.0}; rob_rightcolor [3] = {0.0, 1.0, 0.0}; int main(int argc, char** argv) { rob_size = 1.0; rob_tilt = 0.0; return 0; } // a2.c rob_leftcolor [3] = {1.0, 0.0, 0.0}; </code></pre> <p>Then compile &amp; link them:</p> <pre><code>$ gcc -c a1.c a1.c:2:1: warning: data definition has no type or storage class [enabled by default] a1.c:3:1: warning: data definition has no type or storage class [enabled by default] $ gcc -c a2.c a2.c:1:1: warning: data definition has no type or storage class [enabled by default] $ gcc -o a a1.o a2.o a2.o:(.data+0x0): multiple definition of `rob_leftcolor' a1.o:(.data+0x0): first defined here collect2: error: ld returned 1 exit status </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload