gcc-warning

Why are no strict-aliasing warnings generated for this code?

拈花ヽ惹草 提交于 2019-12-22 08:36:40
问题 I have the following code: struct A { short b; }; struct B { double a; }; void foo (struct B* src) { struct B* b = src; struct A* a = (struct A*)src; b->a = sin(rand()); if(a->b == rand()) { printf("Where are you strict aliasing warnings?\n"); } } I'm compiling the code with the following command line: gcc -c -std=c99 -Wstrict-aliasing=2 -Wall -fstrict-aliasing -O3 foo.c I'm using GCC 4.5.0. I expected the compiler to print out the warning: warning: dereferencing type-punned pointer will

How to make gcc/clang warn about missing breaks in switch statements

拈花ヽ惹草 提交于 2019-12-22 04:49:09
问题 Is there any way to make gcc or clang warn about missing breaks in switch statements? Specifically, I almost always want case statements to end with breaks, and it would be great it I could get the compiler to complain if I don't. Even better would be if it would look for either a break statement or a "// fall through" comment. Is there a different solution people use to help themselves not screw this up? 回答1: With Clang trunk, use -Wimplicit-fallthrough . If you're using C++11, intentional

Difference between double ** and double (*)[2] in C

感情迁移 提交于 2019-12-21 17:30:06
问题 What is the difference between a double ** and a double (*)[2]. If I understand well, a double ** is a pointer to a pointer of double, so it could be a 2D array of any size whereas double (*)[2] is a pointer to an array of double[2]. So if it is right, how can it be passed successfully to a function. For instance in : void pcmTocomplex(short *data, double *outm[2]) if I pass a double (*)[2] as a parameter, I have the following warning : warning: passing argument 2 of ‘pcmTocomplex’ from

How to resolve: “cast to pointer from integer of different size” warning in C code?

走远了吗. 提交于 2019-12-21 09:10:13
问题 I am removing gcc warnings from a legacy code. Is it possible to suppress the warning "cast to pointer from integer of different size" through typecasting: example: some_struct *ptr = func() // func() returns an integer. Can someone please guide me how to resolve such gcc warnings? 回答1: First, if you can fix func (are allowed to modify its source), then fix it. If its computations can be done with pointers, then do them with pointers and return pointers. Sometimes there are valid reasons to

How to disable all warnings in g++ on a few lines of code

久未见 提交于 2019-12-21 05:06:21
问题 How to disable all warnings on a few lines of code. Specific warnings can be disabled using GCC diagnostic feature, but is there a flag for all warnings. I tried this way but it doesn't work #pragma GCC diagnostic push #pragma GCC diagnostic ignored "-wall" // some code #pragma GCC diagnostic pop 回答1: From here: http://dbp-consulting.com/tutorials/SuppressingGCCWarnings.html For version 4.6 or later, you can save the state of the user's diagnostic flags. You can insert this around the line

Floating-point exceptions are signalling in new gfortran version

僤鯓⒐⒋嵵緔 提交于 2019-12-20 04:07:09
问题 I am currently working to debug a subroutine of some software that my boss has written back in the 90s. There seems to be a floating-point exception that occurs in a do loop of a particular subroutine: 16 irad=1,incmax rr1=rr2 rr2=rr2+rdiv if(rr1.gt.rlimit) goto 16 if(pts(irad).gt.0.0) then discrm=(rmsden(mt,irad)/pts(irad)) 1 -((average(mt,irad)**2)/(pts(irad)**2)) else discrm=0.0 endif if(discrm.ge.0.0) then rmsden(mt,irad)=sqrt(discrm) else rmsden(mt,irad)=0.0 endif average(mt,irad)

C++: warning: '…' declared with greater visibility than the type of its field '…::<anonymous>'

北城以北 提交于 2019-12-19 17:46:47
问题 I'm getting these two warnings (with GCC 4.2 on MacOSX): /Users/az/Programmierung/openlierox/build/Xcode/../../src/main.cpp:154:0 /Users/az/Programmierung/openlierox/build/Xcode/../../src/main.cpp:154: warning: 'startMainLockDetector()::MainLockDetector' declared with greater visibility than the type of its field 'startMainLockDetector()::MainLockDetector::<anonymous>' /Users/az/Programmierung/openlierox/build/Xcode/../../src/main.cpp:154:0 /Users/az/Programmierung/openlierox/build/Xcode/../.

C++: warning: '…' declared with greater visibility than the type of its field '…::<anonymous>'

↘锁芯ラ 提交于 2019-12-19 17:46:13
问题 I'm getting these two warnings (with GCC 4.2 on MacOSX): /Users/az/Programmierung/openlierox/build/Xcode/../../src/main.cpp:154:0 /Users/az/Programmierung/openlierox/build/Xcode/../../src/main.cpp:154: warning: 'startMainLockDetector()::MainLockDetector' declared with greater visibility than the type of its field 'startMainLockDetector()::MainLockDetector::<anonymous>' /Users/az/Programmierung/openlierox/build/Xcode/../../src/main.cpp:154:0 /Users/az/Programmierung/openlierox/build/Xcode/../.

gcc over-aligned new support (alignas )

橙三吉。 提交于 2019-12-19 05:44:20
问题 I'm having some difficulty finding more information about GCC's aligned-new warning and the gcc -faligned-new option. Compiling on gcc 7.2.0 (without --std=c++17) and trying to define an aligned struct such as: struct alignas(64) Foo { int x; } Just doing a plain old: Foo * f = new Foo(); Gives me the following warning and suggestion: alignas.cpp:36:25: warning: ‘new’ of type ‘Foo’ with extended alignment 64 [-Waligned-new=] Foo * f = new Foo(); ^ alignas.cpp:36:25: note: uses ‘void* operator

gcc over-aligned new support (alignas )

牧云@^-^@ 提交于 2019-12-19 05:43:59
问题 I'm having some difficulty finding more information about GCC's aligned-new warning and the gcc -faligned-new option. Compiling on gcc 7.2.0 (without --std=c++17) and trying to define an aligned struct such as: struct alignas(64) Foo { int x; } Just doing a plain old: Foo * f = new Foo(); Gives me the following warning and suggestion: alignas.cpp:36:25: warning: ‘new’ of type ‘Foo’ with extended alignment 64 [-Waligned-new=] Foo * f = new Foo(); ^ alignas.cpp:36:25: note: uses ‘void* operator