Telegram Group & Telegram Channel
Зацените, какие штуки оказывается можно делать в си:

#include <stdio.h>

int sum(a, b) int a; long b;
{
return a + b;
}
int main() {
printf("%d\n", sum(1, 3));
return 0;
}

https://godbolt.org/z/TfWhjdb74

Вообще на сишный код не похоже)

Эта штука называется K&R C, но что-то полезное лучше искать по K&R definition style. Такой стиль поддерживается компиляторами си, но не c++.

В частности из-за этого стиля void foo(); это не "функция принимающая 0 аргументов", а "функция без прототипа". Из-за чего такой код компилируется, хотя и может приводить к УБ:


#include <stdio.h>

int sum() {
return 5;
}
int main() {
printf("%d\n", sum(1, 3));
return 0;
}


Однако, в 23 стандарте запретили объявлять функции без прототипов, поэтому там код уже компилироваться не будет:
https://godbolt.org/z/qd4KW4PMc

До 23 стандарта получить ошибку компиляции в таком коде можно, если добавить прототип (тут это уже функция принимающая 0 аргументов):


#include <stdio.h>

int sum(void) {
return 5;
}
int main() {
printf("%d\n", sum(1, 3));
return 0;
}


P.S.
Сам наткнулся на этот факт тут - https://habr.com/en/articles/786096/ (но надо читать еще и комменты, так как в статье есть ошибки)

Более подробно про прототипы можно глянуть вот тут:
https://stefansf.de/post/declaring-defining-and-prototyping-functions/



group-telegram.com/misha_writes_code/206
Create:
Last Update:

Зацените, какие штуки оказывается можно делать в си:


#include <stdio.h>

int sum(a, b) int a; long b;
{
return a + b;
}
int main() {
printf("%d\n", sum(1, 3));
return 0;
}

https://godbolt.org/z/TfWhjdb74

Вообще на сишный код не похоже)

Эта штука называется K&R C, но что-то полезное лучше искать по K&R definition style. Такой стиль поддерживается компиляторами си, но не c++.

В частности из-за этого стиля void foo(); это не "функция принимающая 0 аргументов", а "функция без прототипа". Из-за чего такой код компилируется, хотя и может приводить к УБ:


#include <stdio.h>

int sum() {
return 5;
}
int main() {
printf("%d\n", sum(1, 3));
return 0;
}


Однако, в 23 стандарте запретили объявлять функции без прототипов, поэтому там код уже компилироваться не будет:
https://godbolt.org/z/qd4KW4PMc

До 23 стандарта получить ошибку компиляции в таком коде можно, если добавить прототип (тут это уже функция принимающая 0 аргументов):


#include <stdio.h>

int sum(void) {
return 5;
}
int main() {
printf("%d\n", sum(1, 3));
return 0;
}


P.S.
Сам наткнулся на этот факт тут - https://habr.com/en/articles/786096/ (но надо читать еще и комменты, так как в статье есть ошибки)

Более подробно про прототипы можно глянуть вот тут:
https://stefansf.de/post/declaring-defining-and-prototyping-functions/

BY Миша пишет код




Share with your friend now:
group-telegram.com/misha_writes_code/206

View MORE
Open in Telegram


Telegram | DID YOU KNOW?

Date: |

Ukrainian President Volodymyr Zelensky said in a video message on Tuesday that Ukrainian forces "destroy the invaders wherever we can." At the start of 2018, the company attempted to launch an Initial Coin Offering (ICO) which would enable it to enable payments (and earn the cash that comes from doing so). The initial signals were promising, especially given Telegram’s user base is already fairly crypto-savvy. It raised an initial tranche of cash – worth more than a billion dollars – to help develop the coin before opening sales to the public. Unfortunately, third-party sales of coins bought in those initial fundraising rounds raised the ire of the SEC, which brought the hammer down on the whole operation. In 2020, officials ordered Telegram to pay a fine of $18.5 million and hand back much of the cash that it had raised. "Your messages about the movement of the enemy through the official chatbot … bring new trophies every day," the government agency tweeted. At its heart, Telegram is little more than a messaging app like WhatsApp or Signal. But it also offers open channels that enable a single user, or a group of users, to communicate with large numbers in a method similar to a Twitter account. This has proven to be both a blessing and a curse for Telegram and its users, since these channels can be used for both good and ill. Right now, as Wired reports, the app is a key way for Ukrainians to receive updates from the government during the invasion. "The result is on this photo: fiery 'greetings' to the invaders," the Security Service of Ukraine wrote alongside a photo showing several military vehicles among plumes of black smoke.
from us


Telegram Миша пишет код
FROM American