c89

How to compile for a freestanding environment with GCC?

旧街凉风 提交于 2019-12-18 02:24:07
问题 The code I'm working on is supposed to be possible to build for both hosted and freestanding environments, providing private implementations for some stdlib functions for the latter case. Can I reliably test this with just GCC on a normal workstation/build server? Compile for freestanding environment with GCC The "-ffreestanding" option looked promising, but it seems that it "only" disables built-ins and sets the STDC_HOSTED macro properly, it still provides all system headers. The option "

Is the behavior of subtracting two NULL pointers defined?

落爺英雄遲暮 提交于 2019-12-17 15:54:09
问题 Is the difference of two non-void pointer variables defined (per C99 and/or C++98) if they are both NULL valued? For instance, say I have a buffer structure that looks like this: struct buf { char *buf; char *pwrite; char *pread; } ex; Say, ex.buf points to an array or some malloc'ed memory. If my code always ensures that pwrite and pread point within that array or one past it, then I am fairly confident that ex.pwrite - ex.pread will always be defined. However, what if pwrite and pread are

Which section in C89 standard allows the “implicit int” rule?

耗尽温柔 提交于 2019-12-17 12:18:08
问题 While using gcc , the code: register a = 3; static b = 3; it is allowed while using the -std=c89 -pedantic-errors flags, although there is a warning. However it receive an error with the -std=c99 -pedantic-errors flags. I wonder which section of the C89 standards allows the "implicit int" rule? 回答1: The section that allowed the implicit int rule in C89 would be section 3.5.2 Type specifiers which says ( emphasis mine ): int , signed , signed int , or no type specifiers Keith Thompson in the

Enforce ANSI C Standard in Visual Studio 2015

主宰稳场 提交于 2019-12-13 14:17:21
问题 I am trying to get Visual Studio to enforce the ANSI C standard when compiling a project, but I can't get it to work. Any tips? I have read all the tutorials, I enabled the /Za option, and named my file as .c (not .cpp). However, the following program still builds successfully: #include <stdio.h> void main(void) { for (int i = 0; i < 10; i++) { } int f = 0; } But it shouldn't. It would have to be like this to respect the ANSI C standard: #include <stdio.h> void main(void) { int i; int f = 0;

ANCI C (C90): Can const be changed?

江枫思渺然 提交于 2019-12-13 05:38:45
问题 I am confused as to what ANSI specification says about changing a variable declared const can be legally modified through its address. Unfortunately I do not have access to C90 specification but got conflicting pointers: The keyword const doesn't turn a variable into a constant! A symbol with the const qualifier merely means that the symbol cannot be used for assignment. This makes the value re ad -onl y through that symbol; it does not prevent the value from being modified through some other

variable length structures in C90

我的未来我决定 提交于 2019-12-12 14:05:40
问题 Zero-length arrays are allowed in GNU C. and can be initialized thus struct line { int length; char contents[0]; }; struct line *thisline = (struct line *) malloc (sizeof (struct line) + this_length); thisline->length = this_length; Note: I am referring to this page here: http://gcc.gnu.org/onlinedocs/gcc/Zero-Length.html (provides a basic intro to variable length structures in C) It goes on to say: "In ISO C90, you would have to give contents a length of 1, which means either you waste space

Why do you get different values for integer division in C89?

浪尽此生 提交于 2019-12-12 12:03:23
问题 For example, suppose you have these variables: int i = 9; int j = 7; Depending on the implementation, the value of, (-i)/j , could be either –1 or –2 . How is it possible to get these two different results? 回答1: Surprisingly the result is implementation defined in C89: ANSI draft § 3.3.5 When integers are divided and the division is inexact , if both operands are positive the result of the / operator is the largest integer less than the algebraic quotient and the result of the % operator is

OpenWrt LibUbi implementation

天大地大妈咪最大 提交于 2019-12-12 02:18:17
问题 i'm trying to develop an application (written in ANSI C) for an OpenWrt router using libuci. I've read this useful post: How to find out if the eth0 mode is static or dhcp? and i've develop a piece of my application that is able to read network data (in this case i read if ppp is enabled) using uci library. char path[]="network.ppp.enabled"; struct uci_ptr ptr; struct uci_context *c = uci_alloc_context(); if(!c) return; if (strcmp(typeCmd, "GET") == 0){ if ((uci_lookup_ptr(c, &ptr, path, true

MS VS 2008 and C99

烈酒焚心 提交于 2019-12-11 10:37:05
问题 I read with interest the post "How universally is C99 supported ?". One of the comments therein points that Microsoft doesn't support C99. But the comment symbol // works with VS 2008 and this symbol is in C99. I have two questions: To what extent VS 2008 support C99? Is it ok in the same code to mix C89 and C99 syntax together? So if I write my code in C89 and then place a comment //. This means that I have mixed-coding. So what does the compiler do in such a case? Check my code first with

Allowed operations on an possibly invalid pointer by the strict interpretation of the C Standard

拥有回忆 提交于 2019-12-11 10:06:09
问题 Original Question (please see "Edit: Updated scenario") This question might be a duplicate in one or another way to a huge collection of questions around undefined behavior of pointers to objects that gone out of scope etc. But all questions I found here to this topic are mostly specialized use cases. So I would like to spin the question upside down, not asking if something is forbidden, but WHAT exactly is allowed? To have a possible scenario: You have a function, that takes a pointer - you