Telegram Group & Telegram Channel
Гепардово гнездо
Скомпилируется ли такой код на Си? И если нет, то почему? #include <sys/fcntl.h> #include <sys/types.h> #include <errno.h> #include <unistd.h> #include <stdio.h> typedef struct { int mtime; int size; } Storage; void load(Storage *st) { scanf("%d%d"…
Ответ такой: код не скомпилируется. Даже несмотря на то, что он выглядит довольно безобидно, и явно никаких ошибок не видно.

Разгадка, как правильно указали в комментариях, заключается в следующем.

Где-то в недрах системных заголовков есть struct stat (здесь он прилетает через #include <sys/fcntl.h>) — структура с метаданными файла, которая используется в системном вызове stat. Изначально времена доступа к файлам хранились в этой структуре в полях st_mtime, st_atime, st_ctime в виде UNIX таймстемпа с точностью до секунды. Затем точность повысили до наносекунд и стали использовать struct timespec для задания времени (поля st_atim, st_ctim, st_mtim). А чтобы не ломать обратную совместимость для тех программ, которые про наносекундную точность ничего не знают, вставили вот такой вот костыль:

       #define st_atime  st_atim.tv_sec  /* Backward compatibility */
#define st_mtime st_mtim.tv_sec
#define st_ctime st_ctim.tv_sec


И теперь выходит, что объявление переменной st_mtime дает ошибку, поскольку уже объявлен макрос ровно с таким же именем, и препроцессор раскрывает st_mtime в st_mtim.tv_sec



group-telegram.com/gepardchan/137
Create:
Last Update:

Ответ такой: код не скомпилируется. Даже несмотря на то, что он выглядит довольно безобидно, и явно никаких ошибок не видно.

Разгадка, как правильно указали в комментариях, заключается в следующем.

Где-то в недрах системных заголовков есть struct stat (здесь он прилетает через #include <sys/fcntl.h>) — структура с метаданными файла, которая используется в системном вызове stat. Изначально времена доступа к файлам хранились в этой структуре в полях st_mtime, st_atime, st_ctime в виде UNIX таймстемпа с точностью до секунды. Затем точность повысили до наносекунд и стали использовать struct timespec для задания времени (поля st_atim, st_ctim, st_mtim). А чтобы не ломать обратную совместимость для тех программ, которые про наносекундную точность ничего не знают, вставили вот такой вот костыль:

       #define st_atime  st_atim.tv_sec  /* Backward compatibility */
#define st_mtime st_mtim.tv_sec
#define st_ctime st_ctim.tv_sec


И теперь выходит, что объявление переменной st_mtime дает ошибку, поскольку уже объявлен макрос ровно с таким же именем, и препроцессор раскрывает st_mtime в st_mtim.tv_sec

BY Гепардово гнездо


Warning: Undefined variable $i in /var/www/group-telegram/post.php on line 260

Share with your friend now:
group-telegram.com/gepardchan/137

View MORE
Open in Telegram


Telegram | DID YOU KNOW?

Date: |

Some people used the platform to organize ahead of the storming of the U.S. Capitol in January 2021, and last month Senator Mark Warner sent a letter to Durov urging him to curb Russian information operations on Telegram. "This time we received the coordinates of enemy vehicles marked 'V' in Kyiv region," it added. Following this, Sebi, in an order passed in January 2022, established that the administrators of a Telegram channel having a large subscriber base enticed the subscribers to act upon recommendations that were circulated by those administrators on the channel, leading to significant price and volume impact in various scrips. On Feb. 27, however, he admitted from his Russian-language account that "Telegram channels are increasingly becoming a source of unverified information related to Ukrainian events." Channels are not fully encrypted, end-to-end. All communications on a Telegram channel can be seen by anyone on the channel and are also visible to Telegram. Telegram may be asked by a government to hand over the communications from a channel. Telegram has a history of standing up to Russian government requests for data, but how comfortable you are relying on that history to predict future behavior is up to you. Because Telegram has this data, it may also be stolen by hackers or leaked by an internal employee.
from ua


Telegram Гепардово гнездо
FROM American