Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

why clang++ behaves differently from clang since the former is a symbol link of the latter?

I have a C program that tries to modify a const string literal. As now I learned that this is not allowed.

When I compile the code with clang test.c the compiler gives no warning. But when I compile it with clang++ test.c it gives a warning:

test.c:6:15: warning: conversion from string literal to 'char *' is deprecated [-Wdeprecated-writable-strings] char *s = "hello world"; ^

The problem is that it turns out clang++ is just a symbol link of clang:

ll `which clang++`
lrwxr-xr-x  1 root  admin  5 Jan  1 12:34 /usr/bin/clang++@ -> clang

So my question is how could clang++ behaves differently from clang given that it's a symbol link of clang?

like image 219
RockU Avatar asked Apr 28 '12 00:04

RockU


People also ask

What is the difference between Clang and Clang ++?

The only difference between the two is that clang links against only the C standard library if it performs a link, whereas clang++ links against both the C++ and C standard libraries.

How does Clang work?

Like many other compilers design, Clang compiler has three phase: The front end that parses source code, checking it for errors, and builds a language-specific Abstract Syntax Tree (AST) to represent the input code. The optimizer: its goal is to do some optimization on the AST generated by the front end.

Should I use GCC or Clang?

Clang is much faster and uses far less memory than GCC. Clang aims to provide extremely clear and concise diagnostics (error and warning messages), and includes support for expressive diagnostics. GCC's warnings are sometimes acceptable, but are often confusing and it does not support expressive diagnostics.

What is Clang LLVM?

Clang: a C language family frontend for LLVM. The Clang project provides a language front-end and tooling infrastructure for languages in the C language family (C, C++, Objective C/C++, OpenCL, CUDA, and RenderScript) for the LLVM project.


1 Answers

Clang is looking at its argv[0] and altering its behavior depending on what it sees. This is an uncommon and discouraged, but not rare, trick going at least as far back as 4.2BSD ex and vi, which were the same executable, and probably farther.

In this case, clang is compiling your .c file as C, and clang++ is compiling it as C++. This is a historical wart which you should not rely on; use the appropriate compiler command and make sure that your file extension reflects the true contents of the file.

like image 166
zwol Avatar answered Oct 14 '22 16:10

zwol