如何在Code :: Blocks中使用C11标准 [英] How to use C11 standard in Code::Blocks

查看:268
本文介绍了如何在Code :: Blocks中使用C11标准的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

就像标题所说的那样,我需要制作code::blocks才能与C11一起使用,但我不知道该怎么做.

Like the Title says I need to make code::blocks to work with C11 and I can't figure out how to do it.

我去了settings => compiler settings => Other options,我添加了-std=c11并尝试了-std=gnu11,两者似乎都不起作用.

I went to settings => compiler settings => Other options and I added -std=c11 and tried also with -std=gnu11, both doesn't seems to work.

我编译了gcc-5.2,然后更改了默认编译器(gcc-4.9),但仍然没有结果.

I compiled gcc-5.2 and then I changed the default compiler (gcc-4.9) and still no result.

当我尝试编译以下程序时:

When I try to compile the following program:

#include<stdio.h>

int main(void){
    int arr[] = {0,1,2,3,4};

    for(int i=0;i<5;i++){
        printf("%d ",arr[i]);
    }

    return 0;
}

我得到以下信息:

|6|error: ‘for’ loop initial declarations are only allowed in C99 or C11 mode|


但是如果我在终端(ubuntu 15.04、64BIT,gcc-5.2)中这样做:


But if I do it in terminal (ubuntu 15.04, 64BIT, gcc-5.2):

./install/gcc-5.2.0/bin/gcc5.2 program.c -o program

似乎可以正常工作.

我的问题是,如何使code::blocksc11一起使用?

My question is, how to make code::blocks to work with c11 ?

推荐答案

由于默认情况下GCC 5.x版本与-std=gnu11一起运行,因此Code :: Blocks必须在做某些事情(例如传递-ansi)编译器以使其工作方式有所不同.

Since the GCC 5.x versions run with -std=gnu11 by default, Code::Blocks must be doing something (such as passing -ansi or -std=gnu90) to the compiler to make it work differently.

调查发送到编译器的所有选项.找到一种使Code :: Blocks向您显示其在编译时使用的确切方法的方法.然后找出解决方法.

Investigate all the options that are sent to the compiler. Find a way to have Code::Blocks show you the exact incantation it uses when compiling. Then work out how to fix it.

使用的选项是:

Options that are used are:

-Wall -Wextra -Werror -Wstrict-prototypes -Wconversion -std=gnu11 \
-O0 -g -ansi `pkg-config --cflags gtk+-3.0`

-ansi正在造成损坏;它等效于-std=c90-std=gnu90-显式撤消-std=c11-std=gnu11.

The -ansi is doing the damage; it is equivalent to -std=c90 or perhaps -std=gnu90 — it explicitly undoes -std=c11 or -std=gnu11.

这篇关于如何在Code :: Blocks中使用C11标准的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆