0

If I declare a variable as - extern int c; // I can reuse this variable in another function and no memory is allocated to it.

If I initialize a variable as - uint32 a[32]; // 32*4 bytes of memory is allocated.how to to reuse the above variable in another program ? Example : I am using a pointer to access the value or address of it.

user2984410
  • 39
  • 2
  • 7
  • MAIN.c : extern uint32 a[32]; and try to reuse it in a another program as i – user2984410 Nov 29 '13 at 07:33
  • What do you mean by "another program"? Do you mean like [shared memory](http://en.wikipedia.org/wiki/Shared_memory) between processes? – Some programmer dude Nov 29 '13 at 07:36
  • If you get compiler or linker errors, please edit your question to include them (complete and unedited). Also please edit your question to show a complete code example (also known as a [SSCCE](http://sscce.org/)). You should probably also read [the Stack Overflow question checklist](http://meta.stackexchange.com/questions/156810/stack-overflow-question-checklist), it will help you write better questions in the future. – Some programmer dude Nov 29 '13 at 07:44
  • 1
    @user2984410 Are you talking to yourself? – unwind Nov 29 '13 at 07:47
  • I am extremely sorry for that. – user2984410 Nov 29 '13 at 07:55

1 Answers1

1

Use extern only when you have multiple source files. An extern variable is a declaration of a variable which is defined in another translation unit. Compiler allocates storage when the variable is defined

Refer to THIS POST ON SO for more information

Community
  • 1
  • 1
pratim_b
  • 1,160
  • 10
  • 29