История изменений
Исправление shdown, (текущая версия) :
Нет, сейчас это делается для того, чтобы пользовательские дефайны случайно не сломали всё.
Например, из POSIX:
The <time.h> header shall also declare the itimerspec structure, which has at least the following members:
struct timespec it_interval Timer period. struct timespec it_value Timer expiration.
Если бы там было просто `struct timespec interval`, то можно было бы сломать так:
// vasyan_time_utils.h
#pragma once
#include <stdio.h>
#include <time.h>
#define TS_FMT "%.9f"
#define TS_ARG(ts) ((ts).tv_sec + 1e-9 * (ts).tv_nsec)
#define vasyan_dump_timer(timer) \
do { \
struct itimerspec tmp_; \
timer_gettime((timer), &tmp_); \
printf( \
"{interval=" TS_FMT ", value=" TS_FMT "}\n", \
TS_ARG(tmp_.interval), \
TS_ARG(tmp_.value) \
); \
} while (0)
// main.c
#include <time.h>
#include <stdio.h>
#include <unistd.h>
#include "vasyan_time_utils.h"
#define interval 10
void do_something(void)
{
while (1) {
printf("ЖОПА\n");
sleep(interval);
}
}
int main()
{
timer_t t;
// ...
vasyan_dump_timer(t); // раскроется в «TS_ARG(tmp_.10)»
}
Т.е. для формализации того, какие дефайны может дефайнить пользователь, чтобы они не пересекались с идентификаторами реализации или библиотеки.
Исправление shdown, :
Нет, сейчас это делается для того, чтобы пользовательские дефайны случайно не сломали всё.
Например, из POSIX:
The <time.h> header shall also declare the itimerspec structure, which has at least the following members:
struct timespec it_interval Timer period. struct timespec it_value Timer expiration.
Если бы там было просто `struct timespec interval`, то можно было бы сломать так:
// vasyan_time_utils.h
#pragma once
#include <stdio.h>
#include <time.h>
#define TS_FMT "%.9f"
#define TS_ARG(ts) ((ts).tv_sec + 1e-9 * (ts).tv_nsec)
#define vasyan_dump_timer(timer) \
do { \
struct itimerspec tmp_; \
timer_gettime((timer), &tmp_); \
printf( \
"{interval=" TS_FMT ", value=" TS_FMT "}\n", \
TS_ARG(tmp_.interval), \
TS_ARG(tmp_.value) \
); \
} while (0)
// main.c
#include <time.h>
#include <stdio.h>
#include <unistd.h>
#include "vasyan_time_utils.h"
#define interval 10
void do_something(void)
{
while (1) {
printf("ЖОПА\n");
sleep(interval);
}
}
int main()
{
timer_t t;
// ...
vasyan_dump_timer(t); // раскроется в «TS_ARG(tmp_.10)»
}
Т.е. для формализации того, какие дефайны может дефайнить пользователь, чтобы они не пересекались с идентификаторами реализации или библиотеки.
Исправление shdown, :
Нет, сейчас это делается для того, чтобы пользовательские дефайны случайно не сломали всё.
Например, из POSIX:
The <time.h> header shall also declare the itimerspec structure, which has at least the following members:
struct timespec it_interval Timer period. struct timespec it_value Timer expiration.
Если бы там было просто `struct timespec interval`, то можно было бы сломать так:
// vasyan_time_utils.h
#pragma once
#include <stdio.h>
#include <time.h>
#define TS_FMT "%.9f"
#define TS_ARG(ts) ((ts).tv_sec + 1e-9 * (ts).tv_nsec)
#define vasyan_dump_timer(timer) \
do { \
struct itimerspec tmp_; \
timer_gettime((timer), &tmp_); \
printf( \
"{interval=" TS_FMT ", value=" TS_FMT "}\n", \
TS_ARG(tmp_.interval), \
TS_ARG(tmp_.value) \
); \
} while (0)
// main.c
#include <time.h>
#include <unistd.h>
#include "vasyan_time_utils.h"
#define interval 10
void do_something(void)
{
while (1) {
printf("ЖОПА\n");
sleep(interval);
}
}
int main()
{
timer_t t;
// ...
vasyan_dump_timer(t); // раскроется в «TS_ARG(tmp_.10)»
}
Т.е. для формализации того, какие дефайны может дефайнить пользователь, чтобы они не пересекались с идентификаторами реализации или библиотеки.
Исходная версия shdown, :
Нет, сейчас это делается для того, чтобы пользовательские дефайны случайно не сломали всё.
Например, из POSIX:
The <time.h> header shall also declare the itimerspec structure, which has at least the following members:
struct timespec it_interval Timer period. struct timespec it_value Timer expiration.
Если бы там было просто `struct timespec interval`, то можно было бы сломать так:
// vasyan_time_utils.h
#pragma once
#include <stdio.h>
#include <time.h>
#define TS_FMT "%.9f"
#define TS_ARG(ts) ((ts).tv_sec + 1e-9 * (ts).tv_nsec)
#define vasyan_dump_timer(timer) \
do { \
struct itimerspec tmp_; \
timer_gettime((timer), &tmp_); \
printf( \
"{interval=" TS_FMT ", value=" TS_FMT "}\n", \
TS_ARG(tmp_.interval), \
TS_ARG(tmp_.value) \
); \
} while (0)
// main.c
#include <time.h>
#include <unistd.h>
#include "vasyan_time_utils.h"
#define interval 10
void do_something(void)
{
while (1) {
printf("ЖОПА\n");
sleep(interval);
}
}
int main()
{
timer_t t;
// ...
vasyan_dump_timer(t); // раскроется в «TS_ARG(tmp_.10)»
}