Use of "extern" modifier

Go To Last Post
10 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

In creating a LCD interface file I copied some code for a source I can no longer recall.

 

One line of code used in the LCD_xx.h file was:

 

extern void LCD_Clear(extern void);

 

I understand the extern prefix, however the (extern void) created a compiler error and had to be removed.

 

My question is: smiley

         Is there ever a use for (extern void) in a function?  Or is it simply wrong?

 

Thanks 

JonRob

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 1

Simply wrong.
.
PS forgot to say that something like that would make me question the provenance of the code it appeared in. The Internet is great because it allows good code to be shared to all. But it also allows anyone to post anything, however good or bad. (there's an atrocious LCD library called "MrLcd" for example that has gained widespread use even though it is a steaming pile!

Last Edited: Sun. Jun 11, 2017 - 03:17 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

An void argument is non existent, it doesn't even make any sense to make it external (or static, or const or whatever...).

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Added to which, isn't LCD_clear() pretty much always going to be a parameter less function? So presumably they meant "void" alone?

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I've tried googling to see if I could find where your copied code originally came from but Google is notoriously hopeless at symbol searches (such as () around extern void). I've tried the SymbolHound srarch engine but got no results. I'd be very interested to see the original.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Thanks for the answers.    Now I see,   void is as you say nothing.  So the concept of defining nothing elsewhere makes no sense.

 

Thanks again enlightened

 

JonRob

 

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I also tried google - no success.

 

I guess it's either just a typo, or some over-zealous script that was supposed to just make 'void' functions 'extern void' - but hadn't properly distinguished 'void' parameters!

 

BTW: note that 'extern' on function prototypes is entirely unnecessary (but perfectly valid) - if used, it's purely as a prompt/reminder for the human reader.

 

 

Top Tips:

  1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
  2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
  3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
  4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
  5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
  6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...
Last Edited: Sun. Jun 11, 2017 - 04:37 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

awneil wrote:
BTW: note that 'extern' on function prototypes is entirely unnecessary (but perfectly valid) - if used, it's purely as a prompt/reminder for the human reader.

 

What if it is local to a function? Then it is necessary, but maybe you discount that because it's a horrible way to write code!

Bob. Engineer and trainee Rocket Scientist.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

 

awneil wrote:

BTW: note that 'extern' on function prototypes is entirely unnecessary

donotdespisethesnake wrote:
What if it is local to a function?

Sorry, I don't understand the question - what if what is local to a function?

 

 

Top Tips:

  1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
  2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
  3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
  4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
  5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
  6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...
Last Edited: Sun. Jun 11, 2017 - 08:55 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

@donotdespisethesnake: The original question was explicitly about the bolded 'external' in

 

     extern void LCD_Clear(extern void);

 

Re "what if it was local": It wouldn't make much sense for a local (aka "automatic") variable to be declared external. The 'external' has do to with pointing out that something is in another source file (aka "compilation unit") and something can hardly be local to a function and at the same time not in the source file where this function is.

As of January 15, 2018, Site fix-up work has begun! Now do your part and report any bugs or deficiencies here

No guarantees, but if we don't report problems they won't get much of  a chance to be fixed! Details/discussions at link given just above.

 

"Some questions have no answers."[C Baird] "There comes a point where the spoon-feeding has to stop and the independent thinking has to start." [C Lawson] "There are always ways to disagree, without being disagreeable."[E Weddington] "Words represent concepts. Use the wrong words, communicate the wrong concept." [J Morin] "Persistence only goes so far if you set yourself up for failure." [Kartman]