Enforcing ANSI C89 with clang

I'm trying to make the C compiler clang go into ANSI C89 mode but without success. Here is an example session: $ cat t.c #include <stdio.h> int main(void) { puts(__FUNCTION__); return 0; } $ gcc -pedantic -std=c89 -Wall t.c t.c: In f...
more »

2017-11-29 19:11 (1) Answers

why clang -Wempty-body doesn't detect this case?

After answering Xcode- C programming - While loop, I stopped making theoric answers and installed clang on my Windows box to check if it's really better than gcc in the warning diagnostics department. I'm using -Wempty-body in clang to compile this ...
more »

2017-09-30 15:09 (1) Answers

Force C99 Compliant Compilation in clang

I am trying to write some C99 code that needs to compile on solaris in c99 mode, but I don't have access to a solaris machine. Instead, I'm trying to do this on OSX with clang. However, using (file min.c): #include <stdio.h> #include <st...
more »

2017-09-18 16:09 (2) Answers

Is this use of unions strictly conforming?

Given the code: struct s1 {unsigned short x;}; struct s2 {unsigned short x;}; union s1s2 { struct s1 v1; struct s2 v2; }; static int read_s1x(struct s1 *p) { return p->x; } static void write_s2x(struct s2 *p, int v) { p->x=v;} int test(union...
more »

2017-09-13 21:09 (3) Answers

No compiler warning for obvious segfault

I am surprised this compiles without any warning: int main() { *"abc" = '\0'; } with gcc main.c -Wall -Wextra and clang main.c -Weverything. Why is there no warning for this ? Is there any way this could not raise a segmentation fault ? ...
more »

2017-09-07 16:09 (1) Answers

Android clang LLVM undefined errors

I rooted my android phone and installed termux and clang. When I tried to compile this code: #include <android/sensor.h> int main(){ ASensorManager* sensorManager = ASensorManager_getInstance(); } to access sensors in my phone it gives a b...
more »

2017-07-04 22:07 (0) Answers

Strange Clang behaviour in Xcode 8.3

Recently i noticed strange behaviour with Objective C memory management in Xcode. Here is the code: #import <Foundation/Foundation.h> int main(int argc, const char * argv[]) { @autoreleasepool { NSString *firstString = [[NSString...
more »

2017-05-27 13:05 (1) Answers

Strange behavior in C when comparing integers

This problem is encountered in my mac environment where the gcc version is shown below: Configured with: --prefix=/Library/Developer/CommandLineTools/usr --with-gxx-include-dir=/usr/include/c++/4.2.1 Apple LLVM version 7.0.2 (clang-700.1.81) Target:...
more »

2017-05-23 09:05 (2) Answers

typedef with restrict keyword

I defined aligned floats like this typedef __attribute((aligned(64))) float aligned_float; And then I define aligned floats with the restrict keyword like this typedef aligned_float * restrict aligned_floatptr; This works like I expect. But sin...
more »

2017-04-26 12:04 (0) Answers

Linking position-dependent assembly on Debian

I'm having trouble linking position-dependent assembly using GCC on Debian 9. The following is the hello.s file in assembly: .section .rodata hello_str: .string "Hello world" .text .globl main main: xor %rdi, %rdi mov $hello_str, %rdi ...
more »

2017-03-20 15:03 (0) Answers

Get #included header files after including

Say I've two header files A.hpp and B.hpp and A.hpp gets included in the second file via #include "A.hpp" statement. Now when distributing the header files, I want another option which includes a single header file A_B.hpp which contains exactly the ...
more »

2017-03-12 03:03 (2) Answers

Checking support for _Generic() selection in C

I use macro generic selection to "overload" some functions in my custom library and i want to make it as portable as possible, so i'm trying to check whether generic selection support is present by doing #if ((__STDC_VERSION__>=201112L) || ((__GN...
more »

2017-03-09 15:03 (2) Answers