Puppy Linux Discussion Forum Forum Index Puppy Linux Discussion Forum
Puppy HOME page : puppylinux.com
"THE" alternative forum : puppylinux.info
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

The time now is Mon 19 Nov 2018, 10:00
All times are UTC - 4
 Forum index » Off-Topic Area » Programming
C compilers and cppcheck
Post new topic   Reply to topic View previous topic :: View next topic
Page 1 of 1 [1 Post]  
Author Message
WIckedWitch

Joined: 29 Mar 2018
Posts: 244
Location: West Wales bandit country

PostPosted: Fri 09 Nov 2018, 11:46    Post subject:  C compilers and cppcheck  

Just for a laugh, on a system safety email list, I posted a few programs that show how the FOSS C/C++ checker program cppcheck in some cases does no better than well-known compilers. Have a look at this compact and bijou piece of mischief:

/* cimplex-d-0007.c : tests order of evaluation of function designator and argument list in a function call*/
#include <stdio.h>

static void f0(int n) { printf("\ncall was f0(%i) - func. designator evaluated first\n", n); return; }
static void f1(int n) { printf("\ncall was f1(%i) - argument list is evaluated first\n", n); return; }

/* static void (*fpa[2])(int n) = { f0, f1 };*/

int main(void)
{
int i = 1;

void (*fpa[2])(int n) = { f0, f1 }; /* declare & initialise array of pointers pointing to f0 and f1 */

/* now make a function call to check the order of evaluation of the func. designator and the arg. list */
/* f0(1) occurs if func. designator is evaluated first, f1(0) occurs if argument list is evaluated first */

(*fpa[i=(1-i)])(i=(1-i)); /* note the symmetric double side effect on i here */

return 0;
}



This program tests the order of evaluation of the operands of the function-call operator. Clang and gcc flag the double side-effect but cppcheck and tcc do not.

Worse, cppcheck gives the diagnostic:

cimplex-d-0007.c:18: error: Uninitialized variable: fpa

which is just plain wrong!

In this and other tests. I've found that clang-4.0 does no worse than cppcheck in diagnosis and in some cases does better.

_________________
Sometimes I post mindfully, sometimes not mindfully, and sometimes both mindfully and not mindfully. It all depends on whether and when my mind goes walkies while I'm posting Confused
Back to top
View user's profile Send private message 
Display posts from previous:   Sort by:   
Page 1 of 1 [1 Post]  
Post new topic   Reply to topic View previous topic :: View next topic
 Forum index » Off-Topic Area » Programming
Jump to:  

You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group
[ Time: 0.2656s ][ Queries: 11 (0.2082s) ][ GZIP on ]