Why void [tittle] (void)?

I have juat gotten some SH1106 displays for a project, looking throught the examples for the u8glib.h I noticed that a lot of the void declerration have void for asecond time within the brackets.

void draw(void) {
  // graphic commands to redraw the complete screen should be placed here  
  u8g.setFont(u8g_font_unifont);
  u8g.setPrintPos(0, 20); 
  // call procedure from base class, http://arduino.cc/en/Serial/Print
  u8g.print("Hello World!");
}

I have not seen this before, is there a reason for it? Do i need to worry about doing the same when finally compiling my own programme?
To be honest it seem like a hold over from an older style/system of coding.

1 Like

It is not required but just means nothing will be passed to the function as an argument as far as I am aware

OK, thanks. One less thing to worry about.

It's not a "void" that's being declared but a function.

1 Like

Technically, a function definition void draw{void) means that the function draw takes no arguments and returns no value, while void myfunc() COULD mean "this is an old-style C function that doesn't return a value; the arguments will be mentioned later."
(This "old style function definition" is apparently being removed from the next generation of the C specification. You shouldn't use it, and don't need to know about it!)

Thanks
While I am working with this, this will be the first time I have worked with a character array

#define MENU_ITEMS 3
const char *menu_strings[MENU_ITEMS] = { "Sequence", "Speed", "Brightness"};

I have done some searching but can't seem to find the use of the * at the begining of the array name. If i remove it to say:

#define MENU_ITEMS 3
const char menu_strings[MENU_ITEMS] = { "Sequence", "Speed", "Brightness"};

I get the following:

too many initializers for 'const char [3]'

I m assuming that * is notation to treat each string as a single item within the array.

The '*' notation makes the 'menu_strings' array an array of Pointers. Specifically pointers to 'char' variables.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.