网页资讯视频图片知道文库贴吧地图采购
进入贴吧全吧搜索

 
 
 
日一二三四五六
       
       
       
       
       
       

签到排名:今日本吧第个签到,

本吧因你更精彩,明天继续来努力!

本吧签到人数:0

一键签到
成为超级会员,使用一键签到
一键签到
本月漏签0次!
0
成为超级会员,赠送8张补签卡
如何使用?
点击日历上漏签日期,即可进行补签。
连续签到:天  累计签到:天
0
超级会员单次开通12个月以上,赠送连续签到卡3张
使用连续签到卡
01月23日漏签0天
c语言吧 关注:801,820贴子:4,375,517
  • 看贴

  • 图片

  • 吧主推荐

  • 视频

  • 游戏

  • 10回复贴,共1页
<<返回c语言吧
>0< 加载中...

关于C99,gcc为何与C primer Plus所讲的不同

  • 只看楼主
  • 收藏

  • 回复
  • kjfddfjk
  • 大能力者
    8
该楼层疑似违规已被系统折叠 隐藏此楼查看此楼
刚刚看C primer Plus 6 Edition 12章:Storage Classes 里的scope这样说
Traditionally, variables with block scope had to be declared at the beginning of a block. C99
relaxed that rule, allowing you to declare variables anywhere in a block. One new possibility is in the control section of a for loop. That is, you now can do this:
for (int i = 0; i < 10; i++)
printf("A C99 feature: i = %d", i);
As part of this new feature, C99 expanded the concept of a block to include the code controlled by a for loop, while loop, do while loop, or if statement, even if no brackets are used. So in the previous for loop, the variable i is considered to be part of the for loop block. Therefore, its scope is limited to the for loop. After execution leaves the for loop, the program will no longer see that i .
于是我试了下
#include <stdio.h>
int main(void)
{
for (int i = 0; i < 10; i++)
printf("A C99 feature: i = %d", i);
return 0;
}
编译后提示
error: 'for' loop initial declaration used outside C99 mode
也就是说C99不允许这样做的,不明白到底是哪个错了


  • kjfddfjk
  • 大能力者
    8
该楼层疑似违规已被系统折叠 隐藏此楼查看此楼
gcc版本是3.4.2 mingw专用


2026-01-23 04:54:18
广告
不感兴趣
开通SVIP免广告
  • z什么什么k
  • 彩虹面包
    13
该楼层疑似违规已被系统折叠 隐藏此楼查看此楼
居然还能看到3.4.2这么古老的版本……gcc默认情况下是使用c89标准(不支持随处定义变量),只有在命令行参数中加入-std=c99才会启用对c99的支持……


  • z什么什么k
  • 彩虹面包
    13
该楼层疑似违规已被系统折叠 隐藏此楼查看此楼
目测对 ‘……outside c99 mode’ 报错就能说明只有c99模式下支持这一特性……


登录百度账号

扫二维码下载贴吧客户端

下载贴吧APP
看高清直播、视频!
  • 贴吧页面意见反馈
  • 违规贴吧举报反馈通道
  • 贴吧违规信息处理公示
  • 10回复贴,共1页
<<返回c语言吧
分享到:
©2026 Baidu贴吧协议|隐私政策|吧主制度|意见反馈|网络谣言警示