remove const
This commit is contained in:
parent
2d7c2371e4
commit
98d5a1a3bc
8 changed files with 53 additions and 116 deletions
|
@ -1,5 +1,4 @@
|
|||
int printf(const char format[], ...);
|
||||
int scanf(const char format[], ...);
|
||||
int printf(char* format, ...);
|
||||
|
||||
void should_be(int expected, int actual) {
|
||||
if (expected != actual) {
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
int printf(const char* format, ...);
|
||||
int printf(char* format, ...);
|
||||
|
||||
int main() {
|
||||
printf("hello world %d\n", 42);
|
||||
|
|
46
demo/lut.c
46
demo/lut.c
|
@ -1,46 +0,0 @@
|
|||
int printf(const char format[], ...);
|
||||
int getchar();
|
||||
|
||||
char string_table[65536];
|
||||
int string_offset;
|
||||
int string_lut[4096];
|
||||
int string_lut_size;
|
||||
|
||||
int parse_string() {
|
||||
int offset = string_offset;
|
||||
int ch;
|
||||
while ((ch = getchar()) != '"') {
|
||||
if (ch == -1 || ch == '\n') {
|
||||
printf("expecting '\"'\n");
|
||||
return 1;
|
||||
}
|
||||
string_table[string_offset++] = ch;
|
||||
}
|
||||
string_table[string_offset++] = 0;
|
||||
string_lut[string_lut_size] = offset;
|
||||
return string_lut_size++;
|
||||
}
|
||||
|
||||
|
||||
int streq(const char* s1, const char* s2) {
|
||||
while (*s1 && *s2 && *s1 == *s2) {
|
||||
s1++;
|
||||
s2++;
|
||||
}
|
||||
return *s1 == *s2;
|
||||
}
|
||||
|
||||
void dump_string_table() {
|
||||
printf(".data\n");
|
||||
for (int i = 0; i < string_lut_size; ++i) {
|
||||
char* id = string_table + string_lut[i];
|
||||
printf(".LC%d: .string \"%s\", const: %d\n",
|
||||
i, id, streq(id, "const"));
|
||||
}
|
||||
}
|
||||
|
||||
int main() {
|
||||
char ch;
|
||||
while ((ch = getchar()) == '"') parse_string();
|
||||
dump_string_table();
|
||||
}
|
|
@ -1,4 +1,4 @@
|
|||
int printf(const char format[], ...);
|
||||
int printf(char* format, ...);
|
||||
int putchar(int ch);
|
||||
|
||||
int a[9];
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
int printf(const char format[], ...);
|
||||
int scanf(const char format[], ...);
|
||||
int printf(char* format, ...);
|
||||
int scanf(char* format, ...);
|
||||
|
||||
void sort(int a[], int n) {
|
||||
for (int i = 0; i < n; i++) {
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
int printf(const char* format, ...);
|
||||
int printf(char* format, ...);
|
||||
|
||||
int strcmp(const char* s1, const char* s2) {
|
||||
int strcmp(char* s1, char* s2) {
|
||||
while (*s1 && *s2 && *s1 == *s2) {
|
||||
s1++;
|
||||
s2++;
|
||||
|
@ -9,8 +9,8 @@ int strcmp(const char* s1, const char* s2) {
|
|||
}
|
||||
|
||||
int main() {
|
||||
const char* s1 = "helloworld";
|
||||
const char* s2 = "world";
|
||||
char* s1 = "helloworld";
|
||||
char* s2 = "world";
|
||||
printf("%d\n", strcmp(s1, s2));
|
||||
printf("%d\n", strcmp(s1 + 5, s2));
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue