• AVR Freaks

Hot!Can't understand PIC32M variable visibility

Page: < 12 Showing page 2 of 2
Author
andersm
Super Member
  • Total Posts : 2839
  • Reward points : 0
  • Joined: 2012/10/07 14:57:44
  • Location: 0
  • Status: offline
Re: Can't understand PIC32M variable visibility 2020/07/26 03:52:14 (permalink)
+1 (1)
daveplextern uint8_t gsmbyte = 0;

Look closer at the snippet I posted. Remove the assignment.
#21
davepl
New Member
  • Total Posts : 25
  • Reward points : 0
  • Joined: 2016/06/11 01:01:31
  • Location: 0
  • Status: offline
Re: Can't understand PIC32M variable visibility 2020/07/26 04:31:09 (permalink)
0
Well I've merged tcpip.h with gsm.h and merged tcpip.c with gsm.c and apart from having to remove extern from the gsmflags structure everything is fine
 
#22
davepl
New Member
  • Total Posts : 25
  • Reward points : 0
  • Joined: 2016/06/11 01:01:31
  • Location: 0
  • Status: offline
Re: Can't understand PIC32M variable visibility 2020/07/26 04:36:12 (permalink)
0
andersm
daveplextern uint8_t gsmbyte = 0;

Look closer at the snippet I posted. Remove the assignment.


I saw the note about difference between initialised and uninitialised variables in the manual, I'm going to remove the = 0 part it's not necessary.
#23
davepl
New Member
  • Total Posts : 25
  • Reward points : 0
  • Joined: 2016/06/11 01:01:31
  • Location: 0
  • Status: offline
Re: Can't understand PIC32M variable visibility 2020/07/26 05:08:45 (permalink)
+1 (1)
This shows that the extern keyword actually decreases visibility in a program and if I initialise a variable unless it is within a function it will be globally visible. I also now understand the difference between the words definition and declaration in c. I got this from:
https://www.geeksforgeeks...g-extern-keyword-in-c/
 
So that was a preliminary look at the extern keyword in C.
In short, we can say:
  1. A declaration can be done any number of times but definition only once.
  2. the extern keyword is used to extend the visibility of variables/functions.
  3. Since functions are visible throughout the program by default, the use of extern is not needed in function declarations or definitions. Its use is implicit.
  4. When extern is used with a variable, it’s only declared, not defined.
  5. As an exception, when an extern variable is declared with initialization, it is taken as the definition of the variable as well.
#24
Page: < 12 Showing page 2 of 2
Jump to:
© 2020 APG vNext Commercial Version 4.5