Using the following command
gcc -c -Wall -Wextra -pedantic -ansi -std=c99 -fstack-protector-all -fstack-check -O3 root.c -o rootTESTOBJECT
I get the compiler warning
root.h:76:22: warning: ISO C does not permit named variadic macros
72 #ifdef Debug
73 #include <stdio.h>
74 #define crumb(phrase0...) printf(phrase0)
75 #else
76 #define crumb(phrase0...)
77 #endif
I believe the option
-ansi -std=c99
allows the use of variadic macros, it does according to the docs anyway...
I have tried editing line 76 to
76 #define crumb(phrase0...) printf("")
to see if this fixed the warning but with no joy.
the compiler verion is Apple's gcc, version 4.2.1
I'm not sure if I need be too concerned by this but I really don't like warnings. What flag's am I missing ?
#define crumb(phrase0...) <whatever> is giving a name (phrase0) to the variable arguments (...).
This is a GCC extension.
C99 does define a way of passing variable arguments to macros (see §6.10.3/12 and §6.10.3.1/2): the variable arguments are unnamed
on the left-hand side of the definitions (i.e. just ...), and referenced on the right-hand side as __VA_ARGS__, like this:
#define crumb(...) printf(__VA_ARGS__)
(By the way, your gcc arguments should not include both -ansi and -std=c99: -ansi specifies the earlier C standard (known variously as ANSI C, C89 or C90); the combination of both options only happens to select C99 in this case because -std=c99 appears after -ansi in the argument list, and the last one wins.)
Related
What exactly does -DPIC do when compiling using GCC, and when is it really necessary?
I found that -fpic and -fPIC are to generate Position Independent Code. But I could not find anything about -DPIC.
This is just a preprocessor macro definition. The GCC manual says:
-D NAME
Predefine NAME as a macro, with definition 1.
-D NAME=DEFINITION
The contents of DEFINITION are tokenized and processed as if they
appeared during translation phase three in a #define directive.
This might be useful if your source code cares whether it's being compiled as position-independent code. For example:
#ifdef PIC
/* ... */
#endif
EDIT Question is: how do I remove the warning /EDIT
compiling (special cut-down test with just one #include)
#include <string.h>
void DeleteMe(){
const char* pC = "ABC";
int nLen = strnlen(pC, 255);
char buffer[256];
strncpy(buffer, pC, nLen);
}
With no dialect, it compiles no warning as
Building file: ../EzyThread.c
Invoking: GCC C Compiler
gcc -O0 -g3 -Wall -c -fmessage-length=0 -MMD -MP -MF"EzyThread.d" -MT"EzyThread.o" -o "EzyThread.o" "../EzyThread.c"
Finished building: ../EzyThread.c
making dialect c99 gives warning
Building file: ../EzyThread.c
Invoking: GCC C Compiler
gcc -std=c99 -O0 -g3 -Wall -c -fmessage-length=0 -MMD -MP -MF"EzyThread.d" -MT"EzyThread.o" -o "EzyThread.o" "../EzyThread.c"
../EzyThread.c: In function ‘DeleteMe’:
../EzyThread.c:4:13: warning: implicit declaration of function ‘strnlen’ [-Wimplicit-function-declaration]
int nLen = strnlen(pC, 255);
^
Finished building: ../EzyThread.c
making dialect c11 (my preferred option) gives warning
Building file: ../EzyThread.c
Invoking: GCC C Compiler
gcc -std=c11 -O0 -g3 -Wall -c -fmessage-length=0 -MMD -MP -MF"EzyThread.d" -MT"EzyThread.o" -o "EzyThread.o" "../EzyThread.c"
../EzyThread.c: In function ‘DeleteMe’:
../EzyThread.c:4:13: warning: implicit declaration of function ‘strnlen’ [-Wimplicit-function-declaration]
int nLen = strnlen(pC, 255);
^
Finished building: ../EzyThread.c
Extra info:
Oher parts of the project fail to compile under c90, so no info available
Running under Ubuntu 16.04 which was an upgrade of 14.04
Using
Eclipse IDE for C/C++ Developers
Version: Neon.3 Release (4.6.3)
Build id: 20170314-1500
man strnlen
gives
STRNLEN(3) Linux Programmer's Manual STRNLEN(3)
NAME
strnlen - determine the length of a fixed-size string
SYNOPSIS
#include <string.h>
size_t strnlen(const char *s, size_t maxlen);
Feature Test Macro Requirements for glibc (see feature_test_macros(7)):
strnlen():
Since glibc 2.10:
_XOPEN_SOURCE >= 700 || _POSIX_C_SOURCE >= 200809L
Before glibc 2.10:
_GNU_SOURCE
On POSIX systems like Linux and macOS, you need define the macro it specifies as the feature test macro, by passing -D_POSIX_C_SOURCE=200809L to the compiler or writing #define _POSIX_C_SOURCE 200809L before the #include.
On Windows, you don’t need any special macros and can just use strnlen directly.
Note that the C standard doesn't actually define strnlen, but instead strnlen_s, which is similar but not quite identical. However, a lot of implementations don’t include it, and even for those which do you might need to define __STDC_WANT_LIB_EXT1__ to 1 before including string.h.
You can use _GNU_SOURCE or _POSIX_C_SOURCE
You can refer to this manual page https://www.man7.org/linux/man-pages/man3/strnlen.3.html
#define _GNU_SOURCE
or
#define _POSIX_C_SOUCRE 200809L
I am compiling with clang++ -pedantic -Werror -std=c++11
C++11 does not support variable length arrays and so the compiler warns when they are used.
g++ supports the -Wno-vla option to stop it from doing this.
This doesn't appear to work in clang++, is there an alternative that does work?
error: variable length arrays are a C99 feature [-Werror,-Wvla-extension]
int a[argc];
^
1 error generated.
clang++ helpfully tells you what flags generated the diagnostic. Just "invert" the flag, in this case: -Wno-vla-extension.
I'd like to use a single (cross-)compiler to compile code for different ARM calling conventions: since I always want to use floating point and NEON instructions, I just want to select the hard-float calling convention or the soft-float (softfp) calling convention.
My compiler defaults to hard-float, but it supports both architectures that I need:
$ arm-linux-gnueabihf-gcc -print-multi-lib
.;
arm-linux-gnueabi;#marm#march=armv4t#mfloat-abi=soft
$
When I compile with the default parameters:
$ arm-linux-gnueabihf-g++ -Wall -o hello_world_armhf hello_world.cpp
It succeeds without any errors.
If I compile with the parameters returned by -print-multi-lib:
$ arm-linux-gnueabihf-g++ -marm -march=armv4t -mfloat-abi=soft -Wall -o hello_world hello_world.cpp
It again compiles without error (By the way, how can I test that the resultant code is hard- or soft-float?)
Unfortunately, if I try this:
$ arm-linux-gnueabihf-g++ -march=armv7-a -mthumb-interwork -mfloat-abi=softfp -mfpu=neon -Wall -o hello_world hello_world.cpp
[...]/gcc/bin/../lib/gcc/arm-linux-gnueabihf/4.7.3/../../../../arm-linux-gnueabihf/bin/ld: error: hello_world uses VFP register arguments, /tmp/ccwvfDJo.o does not
[...]/gcc/bin/../lib/gcc/arm-linux-gnueabihf/4.7.3/../../../../arm-linux-gnueabihf/bin/ld: failed to merge target specific data of file /tmp/ccwvfDJo.o
collect2: error: ld returned 1 exit status
$
I've tested some other permutations of the parameters, but it seems that anything other than the combination shown by -print-multi-lib results in an error.
I've read ARM compilation error, VFP registered used by executable, not object file but the problem there was that some parts of the binary were soft- and some were hard-float. I have a single C++ file to compile...
What parameter(s) I miss to be able to compile with -march=armv7-a -mthumb-interwork -mfloat-abi=softfp -mfpu=neon?
How is it possible that the error is about VFP register arguments while I explicitly have -mfloat-abi=softfp in the command line which prohibits VFP register arguments?
Thanks!
For the records, hello_world.cpp contains the following:
#include <iostream>
int main()
{
std::cout << "Hello, world!" << std::endl;
return 0;
}
You need another compiler with corresponding multilib support.
You can check multilib support with next command.
arm-none-eabi-gcc -print-multi-lib
.;
thumb;#mthumb
fpu;#mfloat-abi=hard
armv6-m;#mthumb#march=armv6s-m
armv7-m;#mthumb#march=armv7-m
armv7e-m;#mthumb#march=armv7e-m
armv7-ar/thumb;#mthumb#march=armv7
cortex-m7;#mthumb#mcpu=cortex-m7
armv7e-m/softfp;#mthumb#march=armv7e-m#mfloat-abi=softfp#mfpu=fpv4-sp-d16
armv7e-m/fpu;#mthumb#march=armv7e-m#mfloat-abi=hard#mfpu=fpv4-sp-d16
armv7-ar/thumb/softfp;#mthumb#march=armv7#mfloat-abi=softfp#mfpu=vfpv3-d16
armv7-ar/thumb/fpu;#mthumb#march=armv7#mfloat-abi=hard#mfpu=vfpv3-d16
cortex-m7/softfp/fpv5-sp-d16;#mthumb#mcpu=cortex-m7#mfloat-abi=softfp#mfpu=fpv5-sp-d16
cortex-m7/softfp/fpv5-d16;#mthumb#mcpu=cortex-m7#mfloat-abi=softfp#mfpu=fpv5-d16
cortex-m7/fpu/fpv5-sp-d16;#mthumb#mcpu=cortex-m7#mfloat-abi=hard#mfpu=fpv5-sp-d16
cortex-m7/fpu/fpv5-d16;#mthumb#mcpu=cortex-m7#mfloat-abi=hard#mfpu=fpv5-d16
https://stackoverflow.com/questions/37418986/how-to-interpret-the-output-of-gcc-print-multi-lib
How to interpret the output of gcc -print-multi-lib
With this configuration gcc -mfloat-abi=hard not only will build your files using FPU instructions but also link them with corresponding libs, avoiding "X uses VFP register arguments, Y does not" error.
The above-mentioned -print-multi-lib output produced by gcc with this patch and --with-multilib-list=armv6-m,armv7,armv7-m,armv7e-m,armv7-r,armv7-a,cortex-m7 configuration option.
If you are interested in building your own gcc with Cortex-A series multilib support, just use --with-multilib-list=aprofile configuration option for any arm*-*-* target without any patches (at list with gcc-6.2.0).
As per Linaro FAQ if your compiler prints arm-linux-gnueabi;#marm#march=armv4t#mfloat-abi=soft then you can only use -march=armv4t. If you want to use -march=armv7-a you need to build compiler yourself.
Following link could be helpful in building yourself GCC ARM Builds
I'm compiling C++ code and I'd like to enable the -pedantic option.
I'm using GCC 4.0, running Xcode on Mac OS X Leopard.
It is for example possible to allow variadic macros and the long long type that are normally forbidden when using -pedantic (with -Wno-variadic-macros and -Wno-long-long).
But I could not find anything to disable the "comma at end of enumerator list" warning.
Is it possible?
Thanks.
A comma at the end of an enumerator is valid in C99 but not in C89, so the following will work providing your code is valid C99
gcc -std=c99 -pedantic foo.c
I'm fairly sure that it's not valid in C++ (according to g++) at all
Edit: tested this with GCC 4.2.1 on HP-UX and it works with no errors / warnings
foo.c
int main(int argc, char** argv) {
enum { A, B, };
return 0;
}
gcc -std=c99 -pedantic foo.c
In C++ it is not yet possible to disable it, even though it legal in C++11.
So in the future, when GCC is corrected, -std=c++11 should disable it.
-std=c99 only works in C, not C++ (as in the question).