关于goto语句

[复制链接]
 楼主| yybj 发表于 2012-6-10 12:06 | 显示全部楼层 |阅读模式
go, GSM, TI, ce, se
首先,不需要提:最好不要用goto的忠告了,这个不是重点,我现在是要用goto的
我在main中有:


GSM:GSM_Reset();


在 timer.c中有语句:
if(voice_delayed>0)
{
voice_delayed--;
goto GSM;
}

头文件包含的顺序是也是先#include "main.h"后#include "timer.h"



编译的时候报错:
Warning[Pe177]: label "GSM" was declared but never referenced

连接的时候报错:
Error[Pe114]: label "GSM" was referenced but not defined


我定义了的,为何不还说没定义?

在IAR帮助文件中找到:

Control flow

……

Rule 14.4 (required)The goto statement shall not be used.
How the rule is checkedThe compiler will generate an error, indicating a violation of this rule, if a goto statement is used.


goto 不能用?

我这样做,

int hour=0;
while(1)
{
if( hour==1)
goto GSM;

……

if(hour==1)
{

input_fp_chck();
GSM:GSM_Reset();
}

……
hour=1;
}

编译通过,连接通过,运行OK.


什么情况?
goto 不能跨文件吗?
火箭球迷 发表于 2012-6-10 12:18 | 显示全部楼层
goto 好像连跨函数都不能做到。
dfsa 发表于 2012-6-10 12:23 | 显示全部楼层
goto的作用域是在函数内部的,想要跨函数,甚至是文件的话,可以试试信号的方式。
无冕之王 发表于 2012-6-10 12:38 | 显示全部楼层
不是goto 的问题 是后面标号的问题吧
您需要登录后才可以回帖 登录 | 注册

本版积分规则

175

主题

2496

帖子

1

粉丝
快速回复 在线客服 返回列表 返回顶部

175

主题

2496

帖子

1

粉丝
快速回复 在线客服 返回列表 返回顶部