c99

How to get into C99 mode in Codeblocks10.05?

落爺英雄遲暮 提交于 2019-12-09 12:11:41
问题 I recently realized that I am not even in C99 mode after receiving the compile error 'for' loop initial declarations are only allowed in C99 mode I found some advice on how to get to C99 via a quick search which has told me to go to Projects -> Properties... But alas, it is greyed out and I am not sure that is even the correct way to fix it (probably not available because my file is not a project, it is a normal source file). I have also seen a lot of similar questions saying to enable C99

size limit of printf conversion specification

随声附和 提交于 2019-12-08 21:04:45
问题 printf conversion specifications are % followed by flags, width, precision, length modifier and conversion specifier. Is there practical limit to size of a conversion specification? I.e. %s is 2 chars long, while %08.2f is 6 chars long. My question is, what is the length of the maximal single specification in a format string that can be created, according to C99 standard? 回答1: There is no such conversion specification of maximum length. If you think you've found such a spec, I can come up

Pointer from integer without a cast

感情迁移 提交于 2019-12-08 18:41:43
问题 When I call a function that expects a pointer, and I pass in a value, I get this warning, and I like that. But when the value happens to be a literal '0', I don't get the warning. I think this is because C think it's null-pointer, and not a value. Is there any way to still get warnings for 0-literals, because I already had some bugs because of it. 回答1: GCC supports a nonnull attribute on function parameters that can do what you want (as long as the -Wnonnull warning option is enabled): void*

Can a int16_t to int conversation result in implementation-defined behavior?

拜拜、爱过 提交于 2019-12-08 15:16:49
问题 In section 7.18.1.1 paragraph 1 of the C99 standard: The typedef name intN_t designates a signed integer type with width N , no padding bits, and a two’s complement representation. According to the C99 standard, exact-width signed integer types are required to have a two's complement representation. This means, for example, int8_t has a minimum value of -128 as opposed to the one's complement minimum value of -127 . Section 6.2.6.2 paragraph 2 allows the implementation to decide whether to

Best practice to declaring counter variables in nested for loops in C99

試著忘記壹切 提交于 2019-12-08 12:24:57
问题 I'm asking which is the best practice between this two implementation: for ( int i = 0; i < 5; i++ ) for ( int j = 0; j < 5; j++ ) ...some code here... ...other code... for ( int i = 0; i < 5; i++ ) for ( int j = 0; j < 5; j++ ) ...some code here... or this one: beginning of function/main int i,j; ...some code... for ( i = 0; i < 5; i++ ) for ( j = 0; j < 5; j++ ) ...some code here... ...other code... for ( i = 0; i < 5; i++ ) for ( j = 0; j < 5; j++ ) ...some code here... In other words is

Why does packing not work across sibling unions or structs

杀马特。学长 韩版系。学妹 提交于 2019-12-08 09:08:33
In the following example I expect the size of complex_t to be the same as uint16_t : 2 bytes, however it's 3 bytes. Removing the second union ("proximity_unsafe") reduces the size to 2 bytes, but I can't figure out the model of the packing rules. #include <stdint.h> #include <stdio.h> typedef union { uint16_t unsafe; struct { uint16_t backwardmotion_unsafe : 1; uint16_t batteryvoltage_unsafe : 1; union { uint16_t dropoff_unsafe : 4; struct { uint16_t dropofffrontleft_unsafe : 1; uint16_t dropofffrontright_unsafe : 1; uint16_t dropoffsideleft_unsafe : 1; uint16_t dropoffsideright_unsafe : 1; }_

Can anybody please explain the behavour of C preprocessor in following examples?

允我心安 提交于 2019-12-08 08:39:25
问题 I am implementing a C macro preprocessor (C99)... I am surprised by the following behaviour.... Ex1: #define PASTE(x) X_##x #define EXPAND(x) PASTE(x) #define TABSIZE 1024 #define BUFSIZE TABSIZE PASTE(BUFSIZE) EXPAND(BUFSIZE) expands to: X_BUFFSIZE X_1024 Ex2: #define EXPAND(s) TO_STRING(s) #define TO_STRING(s) #s #define FOUR 4 TO_STRING(FOUR) EXPAND(FOUR) Expands to: "FOUR" "4" I have gone through the "free" standard of C but I couldn’t find following things... Actually how many passes

Can constant objects with static storage duration and equal, constant initializers be coalesced?

江枫思渺然 提交于 2019-12-08 08:36:33
问题 Consider two objects with static storage duration and equal, constant initializers: static const int a = 50; static const int b = 50; Is it valid for a compiler to combine these such that &a == &b ? (For context, I was thinking of using static constant objects to get unique addresses to use as sentinel pointer values. If it is legal for a compiler to combine such objects and I use the same constant value for two such objects, then the addresses could be equal and I cannot use them as sentinel

How to check that c99 is used, and not gnu99

十年热恋 提交于 2019-12-08 07:06:48
问题 I want to add a warning message during the compilation to warn the user it should use gnu99 instead of c99 (I am using anonymous struct, and it seems it doesn't exist at all in c99). I found that: #if __STDC_VERSION__ >= 199901L but this test is true for c99 and gnu99. Which predefined macro could I use? 回答1: You can check for yourself: $ gcc -std=c99 -dM -E - < /dev/null > c99.txt $ gcc -std=gnu99 -dM -E - < /dev/null > gnu99.txt $ sdiff -s c99.txt gnu99.txt #define __STRICT_ANSI__ 1 < 来源:

C99′s Fixed-Width Integer Types

梦想的初衷 提交于 2019-12-08 05:13:35
问题 Failing to get a detailed answer to my question here. I thought I would tackle it from a different angle. Would someone be able to explain what selection criteria are used for determining the underlying types for C99's fixed-width integer types: [u]int_fast[n]_t [u]int_least[n]_t [u]int[n]_t For a given processor, if 'long' and 'int' are the same size (sizeof(int) == sizeof(long)) then why would 'long' be used over 'int' or vice versa. 回答1: The whim of the author of <stdint.h> . Given that