c11

How to use C11 standard in Code::Blocks

匆匆过客 提交于 2019-12-17 21:59:37
问题 Like the Title says I need to make code::blocks to work with C11 and I can't figure out how to do it. 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. 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; } I

Why does C++11 not support anonymous structs, while C11 does?

血红的双手。 提交于 2019-12-17 16:30:12
问题 C11 supports anonymous structures, like so: struct Foo { struct { size_t x, y; }; }; struct Foo f; f.x = 17; f.y = 42; Basically, the members of such a struct are treated as if they were members of the enclosing struct or union (recursively, if the enclosing structure was itself anonymous). What was the rationale for C++11 not also including anonymous structures? They're only uncommonly useful (mostly inside unions, to eliminate the typing of an identifier for the struct ), certainly. But

Which object declarations in C cause storage to be reserved (i.e. are definitions)?

*爱你&永不变心* 提交于 2019-12-17 16:29:42
问题 C11 specifies in section 6.7 which declarations are also definitions: A definition of an identifier is a declaration for that identifier that: — for an object, causes storage to be reserved for that object; [...] I didn't find a comprehensive list of which object declarations cause storage to be reserved. Intuitively it is clear to me, but I wasn't able to get this information out of the C11 standard. 回答1: There's no definitive list because the standard just describes what are definitions and

Assignment operator sequencing in C11 expressions

≯℡__Kan透↙ 提交于 2019-12-17 12:19:09
问题 Introduction The C11 standard (ISO/IEC 9899:2011) has introduced a new definition of side effect sequencing within an expression (see related question). The sequence point concept has been complemented with sequenced before and sequenced after relations which are now the basis for all definitions. Section 6.5 "Expressions", point 2 says: If a side effect on a scalar object is unsequenced relative to either a different side effect on the same scalar object or a value computation using the

How to extract the source filename without path and suffix at compile time?

Deadly 提交于 2019-12-17 10:35:14
问题 Using both gcc with -std=c11 and g++ with -std=c++14. E.g. for a file named src/dir/Hello.cxx it should expand to something like e.g.: const char basename[] = "Hello"; or const char basename[] = getStaticBasename(__FILE__); as where getStaticBasename() is a macro (for C sources) or constexpr function (for C++ sources) which results to "Hello". I have to avoid splitting the string from __FILE__ at runtime, because the path and suffix must not be compiled into the executable in any way. The

Why didn't gcc implement _s functions?

跟風遠走 提交于 2019-12-17 09:52:40
问题 _s functions, such as scanf_s , printf_s seems to be optional standard. MSVC has implemented these functions, but gcc hasn't. Is there specific reason for not implementing secure functions? Is scanf of gcc secure enough? 回答1: The _s functions are optional (Annex K of the C11 standard). They're widely regarded as 'not very beneficial'. In the answers to my question Do you use the TR-24731 "safe" functions?, you can find information about where there are problems with the standard specification

What is the default C mode for the current gcc (especially on Ubuntu)?

断了今生、忘了曾经 提交于 2019-12-17 05:46:05
问题 When I ask to see the current version of cc I get this. $ cc --version cc (Ubuntu/Linaro 4.7.2-2ubuntu1) 4.7.2 Copyright (C) 2012 Free Software Foundation, Inc. This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. $ What I would like to know is which of c89, c90, c99 or c11 is being used. 回答1: This is explained in depth in the gcc manual, available (if it's installed) by typing info gcc or online

When are anonymous structs and unions useful in C11?

戏子无情 提交于 2019-12-17 01:00:33
问题 C11 adds, among other things, 'Anonymous Structs and Unions'. I poked around but could not find a clear explanation of when anonymous structs and unions would be useful. I ask because I don't completely understand what they are. I get that they are structs or unions without the name afterwards, but I have always (had to?) treat that as an error so I can only conceive a use for named structs. 回答1: Anonymous union inside structures are very useful in practice. Consider that you want to

C99 - vscanf for dummies? [closed]

拥有回忆 提交于 2019-12-13 20:34:11
问题 It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center. Closed 6 years ago . I am sorry to bother S.O. with such a general request for information. I can find plenty of very terminology-heavy definitions of vscanf - but I can't find much in the way of concrete examples which will show

Can I return pointer to VLA?

两盒软妹~` 提交于 2019-12-13 19:17:18
问题 Is such function prototype valid in C? int (*func())[*]; And if it is, how can I define such functions? 回答1: From the C Standard (6.2.1 Scopes of identifiers) ...(A function prototype is a declaration of a function that declares the types of its parameters .) and (6.7.6.2 Array declarators) ...If the size is * instead of being an expression, the array type is a variable length array type of unspecified size, which can only be used in declarations or type names with function prototype scope ;