в случае void вы можете вызвать функцию без параметров, потому что null тоже подходит, а можете с любым количеством параметров любого типа, и затем уже в функции их интерпретировать.
void
нет стандартной возможности интерпретировать переданные ей параметры, поскольку нет ничего, что можно было бы передать вторым параметром в макрос va_start
.если вы объявите функцию без параметров, то при попытке вызвать с параметрами, будет ошибка компиляции
The empty list in a function declarator that is not part of a
definition of that function specifies that no information about the number or types of the
parameters is supplied.
void foo();
void bar(void)
{
foo(1, 1., "");
}
int main(void) { // функция main, которая ...
void означает, что тип аргументов не определен и необязателен.
The special case of an unnamed parameter of type void as the only item in the list
specifies that the function has no parameters.
An identifier list declares only the identifiers of the parameters of the function. An empty
list in a function declarator that is part of a definition of that function specifies that the
function has no parameters.
она вам надо c autotools мучиться?
$ cat test.cpp
class A {
public:
A()
{
}
void bar()
{
}
};
void baz()
{
A foo();
foo.bar();
}
$ g++ -c test.cpp
test.cpp: In function ‘void baz()’:
test.cpp:16:6: error: request for member ‘bar’ in ‘foo’, which is of functional type ‘A()’
16 | foo.bar();
| ^~~
test.cpp:14:4: note: ‘A foo()’ is a function declaration, not a default-constructed object
14 | A foo();
| ^~~
int stled
два раза.void callback(char* topic, byte* payload, int new_pwm, unsigned int length) {
Serial.println();
Serial.print(topic); // выводим в сериал порт название топика
Serial.print(" => ");
for (int i = 0; i < length; i++) {
Serial.print((char)payload[i]);
} // выводим в сериал порт значение полученных данных
String strTopic = String(topic); //получаем название топика
if (strTopic == "home/kinozal/led") //проверяем из нужного ли топика пришли данные
{
payload[length] = 0; //чистим от мусора, длинна строки
String strPayload = String((char*)payload); //считываем значение топика
int val = strPayload.toInt(); //конвертируем для шим
int stled = map(val, 0, 100, 0, 255); //приводим значение 0-100 в значение 255-0
set_pwm_smooth(stled);
Serial.print(" => ");
}
}