Go Down

Topic: void loop(void) vs void loop() (Read 5633 times) previous topic - next topic

Gabriel_swe

Usually code is only
Code: [Select]

void setup()

void loop()


but sometimes I see code that use void inside the parenthesis
Code: [Select]

void setup(void)

void loop(void)


With my limited C knowledge I can't see there is any difference. Am I right in my assumption?

Delta_G

There is no difference at all.  With an empty set of parenthesis the function is assumed to take nothing (ie void) as an argument. 
|| | ||| | || | ||  ~Woodstock

Please do not PM with technical questions or comments.  Keep Arduino stuff out on the boards where it belongs.

Arduino_n00b

Ugh...


It's for reasons like this that noobs such as myself get confused, misled, and even made fun of. >:(

Here's an example that should be updated or down-dated: ;D

Code: [Select]
#include <Wire.h>
#include <Adafruit_MCP4725.h>
#define voltsIn A0

Adafruit_MCP4725 dac; // constructor

void setup(void) {
  Serial.begin(9600);
  dac.begin(0x60); // The I2C Address: Run the I2C Scanner if you're not sure 
 
}

void loop(void) {
 
    uint32_t dac_value;
    int adcValueRead = 0;
    float voltageRead = 0;
   
    float dac_expected_output;
   
   
    for (dac_value = 0; dac_value < 4096; dac_value = dac_value + 15)
    {
      dac_expected_output = (5.0/4096.0) * dac_value;
      dac.setVoltage(dac_value, false);
      delay(250);
      adcValueRead = analogRead(voltsIn);
      voltageRead = (adcValueRead * 5.0 )/ 1024.0;
     
      Serial.print("DAC Value: ");
      Serial.print(dac_value);
     
      Serial.print("\tExpected Voltage: ");
      Serial.print(dac_expected_output,3);
     
      Serial.print("\tArduino ADC Value: ");
      Serial.print(adcValueRead);
     
      Serial.print("\tArduino Voltage: ");     
      Serial.println(voltageRead,3);     
    }   
}



The void loop(void) thing should have been tossed out like the BYTE function!

Better yet, keep the void loop(void) fallacy and bring back the BYTE function.

Please don't bite.  :smiley-mr-green:
I'm not an A.I. Avatar yet.

lastchancename

Just like architectural drawings... VOID is a placeholder for NOTHING, or EMPTY

Wherever you see the word void, don't put, or go looking for *anything*, because it won't be there!

Experienced responders have a nose for laziness, (they were beginners once)... Sure, there are trolls, chest-beaters, and pretenders - but the help you'll get here is about as good as it gets - if you try to help youself!.

PerryBebbington


Quote
It's for reasons like this that noobs such as myself get confused, misled, and even made fun of
You have my sympathy with this one. I was taught C by 2 very good friends and agonised over the difference between

Code: [Select]
void function();
and
void function(void);

I guess it was so obvious to my friends that they are the same they didn't see any reason to tell me! I wasted a lot of time trying to work out how they were different.


slipstick

Some people like being able to do a thing in several different ways.

Some people seem to take that ability as a personal affront intended solely to confuse them.

Once you've recognised that void is a just a way of explicitly saying "You can look away now, there's definitely nothing here" it's pretty obvious (as many things are...after you've learned them!).

Steve

noob314

#6
Dec 06, 2019, 11:20 am Last Edit: Dec 06, 2019, 01:59 pm by noob314
There is several standard revisions for C and C++, but I do not think there is a specific requirement for this case. I believe it is stay the same from initial Kernighan and Ritchie's C definition - both versions are acceptable.

UKHeliBob

Quote
Some people like being able to do a thing in several different ways.

Some people seem to take that ability as a personal affront intended solely to confuse them.
It sounds like you have met my wife !
Please do not send me PMs asking for help.  Post in the forum then everyone will benefit from seeing the questions and answers.

Go Up