更新 6.0s1.h

This commit is contained in:
rabix 2024-06-07 09:37:16 +08:00
parent b9a0f5d158
commit 693fa9e5f6
1 changed files with 8 additions and 6 deletions

14
6.0s1.h
View File

@ -1,13 +1,15 @@
#ifndef S1_6_0_H #ifndef S1_6_0_H
#define S1_6_0_H #define S1_6_0_H
#include <inttypes.h>
struct s1_location { struct s1_location {
const char *file; const char *file;
int line; int line;
}; };
typedef int s1_int; typedef int32_t s1_int;
typedef long long s1_long; typedef int64_t s1_long;
typedef double s1_double; typedef double s1_double;
typedef char s1_char; typedef char s1_char;
@ -37,12 +39,12 @@ void s1_trace(const char *text, struct s1_location loc) {
// 2. simple IO // 2. simple IO
void write_int(s1_int value, struct s1_location loc) { void write_int(s1_int value, struct s1_location loc) {
int rc = printf("%d", value); int rc = printf(PRId32, value);
s1_assert(rc != EOF, "Error: write_int", loc); s1_assert(rc != EOF, "Error: write_int", loc);
} }
void write_long(s1_long value, struct s1_location loc) { void write_long(s1_long value, struct s1_location loc) {
int rc = printf("%lld", value); int rc = printf(PRId64, value);
s1_assert(rc != EOF, "Error: write_long", loc); s1_assert(rc != EOF, "Error: write_long", loc);
} }
@ -63,14 +65,14 @@ void write_char(s1_char value, struct s1_location loc) {
s1_int read_int(struct s1_location loc) { s1_int read_int(struct s1_location loc) {
s1_int value = 0; s1_int value = 0;
int rc = scanf("%d", &value); int rc = scanf(SCNd32, &value);
s1_assert(rc == 1, "Error: read_int", loc); s1_assert(rc == 1, "Error: read_int", loc);
return value; return value;
} }
s1_long read_long(struct s1_location loc) { s1_long read_long(struct s1_location loc) {
s1_long value = 0; s1_long value = 0;
int rc = scanf("%lld", &value); int rc = scanf(SCNd64, &value);
s1_assert(rc == 1, "Error: read_long", loc); s1_assert(rc == 1, "Error: read_long", loc);
return value; return value;
} }