7_13发现了一个小问题为啥在do_line函数里赋值语句在变量定义语句之前就会报错?
来源:互联网 发布:三菱fx2n pid编程手册 编辑:程序博客网 时间:2024/05/29 17:06
1.在变量定义之前出错:
<bldc:/home/tingbinz/apue.3e/SBSCODE/7>R*_*G:vim 7_13.c
1 #include "apue.h"
2 #include <setjmp.h>
3 #define TOKEN 5
4 void do_line (char *ptr);
5 void cmd_add (void);
6 int get_token(void);
7 #define MAXLINE 1024
8
9 jmp_buf jmpbuffer;
10
11 int main()
12 {
13 char line[MAXLINE];
14 if (setjmp(jmpbuffer) != 0)
15 printf("error");
16 while (fgets(line,MAXLINE,stdin) != NULL){
17 do_line(line);
18 }
19 exit(0);
20 }
21
22 char *tok_ptr;
23
24 void do_line(char *ptr)
25 {
26 //tok_ptr = ptr;
27 tok_ptr = ptr;
28 int cmd;
29
30 //tok_ptr = ptr;
31 while ( (cmd = get_token()) > 0){
32 switch (cmd){
33 case TOKEN:
34 cmd_add();
35 break;
36 }
37 }
38
39 }
40
41 int get_token(void)
42 {
43 /* fetch the next token from the line pointed to by tok_ptr;*/
44 }
45
46 void cmd_add(void)
47 {
"7_13.c" 53L, 761C written
<bldc:/home/tingbinz/apue.3e/SBSCODE/7>R*_*G:gcc -Wall -ggdb3 setlongjmp 7_13.c
gcc: setlongjmp: No such file or directory
7_13.c:7: warning: `MAXLINE' redefined
apue.h:29: warning: this is the location of the previous definition
In file included from apue.h:132,
from 7_13.c:1:
error.c: In function `err_doit':
error.c:121: warning: implicit declaration of function `vsnprintf'
error.c:123: warning: implicit declaration of function `snprintf'
7_13.c: In function `do_line':
7_13.c:28: parse error before `int'
7_13.c:31: `cmd' undeclared (first use in this function)
7_13.c:31: (Each undeclared identifier is reported only once
7_13.c:31: for each function it appears in.)
7_13.c:34: warning: unreachable code at beginning of switch statement
7_13.c: In function `get_token':
7_13.c:44: warning: control reaches end of non-void function
挪到变量定义之后 不再出错。
<bldc:/home/tingbinz/apue.3e/SBSCODE/7>R*_*G:vim 7_13.c
1 #include "apue.h"
2 #include <setjmp.h>
3 #define TOKEN 5
4 void do_line (char *ptr);
5 void cmd_add (void);
6 int get_token(void);
7 #define MAXLINE 1024
8
9 jmp_buf jmpbuffer;
10
11 int main()
12 {
13 char line[MAXLINE];
14 if (setjmp(jmpbuffer) != 0)
15 printf("error");
16 while (fgets(line,MAXLINE,stdin) != NULL){
17 do_line(line);
18 }
19 exit(0);
20 }
21
22 char *tok_ptr;
23
24 void do_line(char *ptr)
25 {
26 //tok_ptr = ptr;
27 int cmd;
28
29 tok_ptr = ptr;
30 while ( (cmd = get_token()) > 0){
31 switch (cmd){
32 case TOKEN:
33 cmd_add();
34 break;
35 }
36 }
37
38 }
39
40 int get_token(void)
41 {
42 /* fetch the next token from the line pointed to by tok_ptr;*/
43 }
44
45 void cmd_add(void)
46 {
47 int token;
"7_13.c" 52L, 743C written
<bldc:/home/tingbinz/apue.3e/SBSCODE/7>R*_*G:gcc -Wall -ggdb3 setlongjmp 7_13.c
gcc: setlongjmp: No such file or directory
7_13.c:7: warning: `MAXLINE' redefined
apue.h:29: warning: this is the location of the previous definition
In file included from apue.h:132,
from 7_13.c:1:
error.c: In function `err_doit':
error.c:121: warning: implicit declaration of function `vsnprintf'
error.c:123: warning: implicit declaration of function `snprintf'
7_13.c: In function `get_token':
7_13.c:43: warning: control reaches end of non-void function
求解释。
- 7_13发现了一个小问题为啥在do_line函数里赋值语句在变量定义语句之前就会报错?
- 复杂的表达式放在循环语句里会报错
- 在case语句中定义变量的问题
- 在case语句中定义变量的问题
- 在case语句中定义变量的问题
- 我在用WebService是为啥会报这样一个异常?
- C语言的变量声明在其它语句之前
- C语言的变量声明在其它语句之前
- 一个在构造函数中定义变量的问题
- c程序的变量定义必须在所有函数之前?!
- php 里一个sql语句太长,调式时发现sql语句变得不完整了
- 关于一个STM32编译报错问题,变量声明不能在语句后面
- 遇到的问题-----------定义一个全局变量,在page_load里赋值,但在其他按钮中调用仍为空
- 在telnet 里发现了一个很有趣的网站!
- 关于在case语句中变量的定义
- .c中变量必须定义在执行语句前面
- 发现了一个小问题
- 我了个去,在建行网站里面发现一个小问题
- 统计各班成绩第一名的同学信息
- 代码解决 有些浏览器不支持placeholder特性的问题
- 关于oc的学习笔记 -copy和mutableCopy
- 关于textview的限制文本字数的问题会汇总
- IOS项目集成ShareSDK实现第三方登录、分享、关注等功能。
- 7_13发现了一个小问题为啥在do_line函数里赋值语句在变量定义语句之前就会报错?
- openwrt默认开机启动ssh的方法
- Android反射机制实现与原理
- JS区分中英文字符的两种方法
- EntityFramework 执行SQL语句进行参数化查询代码示例
- 弱符号与强符号概念
- 坐飞机的流程
- 64位系统vs2010平台下实现C++与matlab R2014混合编程方法示例
- 数字电视专业术语--DTV名词扫盲