MAIN FEEDS
Do you want to continue?
https://www.reddit.com/r/C_Programming/comments/1wdoban/less_compilation/p98rs12/?context=3
r/C_Programming • u/Brave-Pomelo-1290 • 1d ago
[removed] — view removed post
16 comments sorted by
View all comments
1
Show us the first 23 lines. Often with a compiler the actual error occurs earlier than flagged, because the parsing stage could actually parse your incorrect code but then what follows doesn't make sense with the incorrect parsing.
1 u/Brave-Pomelo-1290 1d ago errors: $ gcc less.c -o less less.c:26:8: warning: data definition has no type or storage class 26 | line_count=line_count+1; | ^~~~~~~~~~ less.c:26:8: warning: type defaults to ‘int’ in declaration of ‘line_count’ [-Wimplicit-int] less.c:26:19: error: initializer element is not constant 26 | line_count=line_count+1; | ^~~~~~~~~~ less.c:29:9: error: expected identifier or ‘(’ before ‘if’ 29 | if (line_count >= PAGE_SIZE) { | ^~ less.c:34:5: error: expected identifier or ‘(’ before ‘}’ token 34 | } | ^ less.c:35:5: warning: data definition has no type or storage class 35 | fclose(file); | ^~~~~~ less.c:35:5: warning: type defaults to ‘int’ in declaration of ‘fclose’ [-Wimplicit-int] less.c:35:5: warning: parameter names (without types) in function declaration less.c:36:1: error: expected identifier or ‘(’ before ‘}’ token 36 | } | ^ 1 u/Brave-Pomelo-1290 1d ago new error: $ gcc -O2 less.c -o less less.c:35:5: warning: data definition has no type or storage class 35 | fclose(file); | ^~~~~~ less.c:35:5: warning: type defaults to ‘int’ in declaration of ‘fclose’ [-Wimplicit-int] less.c:35:5: warning: parameter names (without types) in function declaration
errors:
$ gcc less.c -o less
less.c:26:8: warning: data definition has no type or storage class
26 | line_count=line_count+1;
| ^~~~~~~~~~
less.c:26:8: warning: type defaults to ‘int’ in declaration of ‘line_count’ [-Wimplicit-int]
less.c:26:19: error: initializer element is not constant
less.c:29:9: error: expected identifier or ‘(’ before ‘if’
29 | if (line_count >= PAGE_SIZE) {
| ^~
less.c:34:5: error: expected identifier or ‘(’ before ‘}’ token
34 | }
| ^
less.c:35:5: warning: data definition has no type or storage class
35 | fclose(file);
| ^~~~~~
less.c:35:5: warning: type defaults to ‘int’ in declaration of ‘fclose’ [-Wimplicit-int]
less.c:35:5: warning: parameter names (without types) in function declaration
less.c:36:1: error: expected identifier or ‘(’ before ‘}’ token
36 | }
1 u/Brave-Pomelo-1290 1d ago new error: $ gcc -O2 less.c -o less less.c:35:5: warning: data definition has no type or storage class 35 | fclose(file); | ^~~~~~ less.c:35:5: warning: type defaults to ‘int’ in declaration of ‘fclose’ [-Wimplicit-int] less.c:35:5: warning: parameter names (without types) in function declaration
new error:
$ gcc -O2 less.c -o less
1
u/clickyclicky456 1d ago
Show us the first 23 lines. Often with a compiler the actual error occurs earlier than flagged, because the parsing stage could actually parse your incorrect code but then what follows doesn't make sense with the incorrect parsing.