c99

How do most embedded C compilers define symbols for memory mapped I/O?

萝らか妹 提交于 2019-12-25 01:38:13
问题 I often times write to memory mapped I/O pins like this P3OUT |= BIT1; I assumed that P3OUT was being replaced with something like this by my preprocessor: *((unsigned short *) 0x0222u) But I dug into an H file today and saw something along these lines: volatile unsigned short P3OUT @ 0x0222u; There's some more expansion going on before that, but it is generally that. A symbol '@' is being used. Above that there are some #pragma's about using an extended set of the C language. I am assuming

How do I suppress PC-Lint errors for C99-style initialization of structure members?

本小妞迷上赌 提交于 2019-12-24 17:46:41
问题 I am using PC-Lint 8.00x with the following options: +v -wlib(1) +fan +fas I receive a number of error messages from PC-Lint when I run code similar to the following: typedef union { struct { unsigned int a : 4; unsigned int b : 4; unsigned int c : 4; unsigned int d : 4; } bits; unsigned short value; } My_Value; int main (void) { My_Value test[] = { { .bits.a = 2, .bits.b = 3, //Errors 133 and 10 .bits.c = 2, .bits.d = 3, }, { .bits.a = 1, .bits.b = 1, //Errors 133 and 10 .bits.c = 1, .bits.d

How can I align a string literal to an address which is multiple of 4?

核能气质少年 提交于 2019-12-24 14:59:19
问题 I'd like to ensure that a given string literal ends up at an address that is a multiple of 2, or even better, 4. Is there any way to achieve that, preferably without using any compiler-specific extensions? Or is it impossible? I'd like to do this so the lowermost bits of the string address are 0 and can be (ab)used as tag bits. 回答1: In C99 you can do this using a union, for example #define ALIGNED_STR_UNION(N, S) const union { char s[sizeof S]; int align; } N = { S } ALIGNED_STR_UNION(sssu,

Are conformant array parameters VLAs?

江枫思渺然 提交于 2019-12-24 10:39:41
问题 CERT's Secure Coding Standard includes an item (API05-C) which encourages the use of conformant array parameters, which is a recommendation I've implemented in a lot of my code (hidden behind a macro for compilers which don't support them). For those who don't know, a conformant array parameter is something like: void foo(int length, char data[length]); API05-C provides more information. Lots of compilers don't like variable-length arrays (for good reason). C11 demotes them from required (as

Why is C99's bool a macro rather than a typedef?

痞子三分冷 提交于 2019-12-24 08:59:26
问题 Why does the boolean type support introduced in C99 use the preprocessor rather than the language's own facilities? Specifically, why do we have: #define bool _Bool #define true 1 #define false 0 in <stdbool.h> rather than: typedef _Bool bool; enum { false = 0, true = 1 }; I guess the enum can be seen as a matter of taste. But - why not have a typedef? 回答1: From section 7.18/3 of the C11 specification: The remaining three macros are suitable for use in #if preprocessing directives. The

Does `recv` work with bytes or octets, or are they one and the same in the context of POSIX documentation?

半腔热情 提交于 2019-12-24 03:09:38
问题 Reading the POSIX reference for socket send at http://pubs.opengroup.org/onlinepubs/009695399/functions/send.html I wonder, what exactly do they mean by "byte" - its traditional/historical meaning, its implied/popular meaning, or something else entirely? I am developing a binary TCP/IP-supported network protocol client-server program, and I would like to properly declare my buffer that I use to pass to recv , and being able to properly unpack its data. Yes, I know it's almost hypothetical

How to change the compiler of VS?

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-24 02:07:10
问题 I'm using VS 2010. I have changed the settings for compiler C code instead of C++. It works fine, but the problem is MS compilers don't supports C99 standard,for this reason I'm looking for a C compiler that can works with VS 10. How to do this? Thanks in advance. 回答1: MS visual studio don't support c99, however they have implemented certain features of c99. From this Microsoft page, their reply for c99 support: Question by a user: "I would like to see C99 support available in Visual Studio.

How to correctly and safely free() all memory used a nested struct in C?

余生颓废 提交于 2019-12-23 23:51:08
问题 I have four different layers of struct nested. The code is as follows: typedef struct System system; typedef struct College college; typedef struct Student student; typedef struct Family family; #define MAX_COLLEGES 10 #define MAX_NAME_LEN 32 #define MAX_STUDENTS 10 struct System { college *Colleges[MAX_COLLEGES]; }; struct College { char name[MAX_NAME_LEN]; student *Students[MAX_STUDENTS]; }; struct Student { char name[MAX_NAME_LEN]; int id; family *fam; //was typo familiy }; struct Family {

MinGW Compiler for Windows, using GCC, C99 vs GNU99

限于喜欢 提交于 2019-12-23 20:04:36
问题 I am using the MinGW compiler for Windows. I am making some programs in C. Most of the articles I read up on this seem to be outdated... last I read C99 was incomplete in the GCC is this still true? My real question is cross platform compatibility between setting C99 and GNU99... should I avoid using GNU99 setting and it's extensions and just stick with C99? I am new to this MinGW compiler set as I have always used Visual Studio and decided to try something new... right now I am compiling

How to access array of flexible arrays in cache friendly manner?

两盒软妹~` 提交于 2019-12-23 19:05:38
问题 I have records with flexible array member typedef struct record { unsigned foo; signed bar; double number[]; } record; I have multiple records with the same amount of numbers so I can arrange them in array. I would like to allocate them into one continuous memory space. const unsigned numbers = ...; const unsigned records = ...; const size_t record_size = sizeof(record) + numbers*sizeof(double); record *prec = malloc(records*record_size); So now I know record_size and I can access it but what