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: |

On February 27th, Durov posted that Channels were becoming a source of unverified information and that the company lacks the ability to check on their veracity. He urged users to be mistrustful of the things shared on Channels, and initially threatened to block the feature in the countries involved for the length of the war, saying that he didn’t want Telegram to be used to aggravate conflict or incite ethnic hatred. He did, however, walk back this plan when it became clear that they had also become a vital communications tool for Ukrainian officials and citizens to help coordinate their resistance and evacuations. 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. But the Ukraine Crisis Media Center's Tsekhanovska points out that communications are often down in zones most affected by the war, making this sort of cross-referencing a luxury many cannot afford. For Oleksandra Tsekhanovska, head of the Hybrid Warfare Analytical Group at the Kyiv-based Ukraine Crisis Media Center, the effects are both near- and far-reaching. One thing that Telegram now offers to all users is the ability to “disappear” messages or set remote deletion deadlines. That enables users to have much more control over how long people can access what you’re sending them. Given that Russian law enforcement officials are reportedly (via Insider) stopping people in the street and demanding to read their text messages, this could be vital to protect individuals from reprisals.
from cn


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