Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [cdt-dev] CODAN question for function can not be resolved AND invalid arguments!

C allows calling undeclared functions NOT undefined functions (linker complains about that later on) but assumptions are made about it (int is assumed as return type and any kind and number of parameters are allowed). 

 

That’s why for example “EC-A A measurement based safer subset of ISO C” considers the following rule.

 

4.3.3 F COMP: All function call arguments and function definition parameters shall be compatible with the corresponding arguments in the corresponding function declaration.

 

Now about argument ‘a’ it was a really bad example from my side.  I apologize for that.  That’s perfectly castable to double.

 

However I tried several arguments going even to the no sense field but nothing seems to produce a warning or error.

 

H_function(“string”)

h_function((char*) 0)

h_function((char*) 0, "str", main)

 

The referred file Sample.c is within the source directory.

 

On the other hand when I tried all this in a C++ project NOT a C project the invalid arguments are wonderfully detected.

 

Curiously for the C++ project I did not customize any rule and it worked flawlessly for detecting the wrong arguments.

 

Should NOT it detect the invalid arguments also for the C type project?

 

Thanks again,

Felipe

 

From: cdt-dev-bounces@xxxxxxxxxxx [mailto:cdt-dev-bounces@xxxxxxxxxxx] On Behalf Of Tomasz Wesolowski
Sent: Thursday, September 02, 2010 6:16 PM
To: CDT General developers list.
Subject: Re: [cdt-dev] CODAN question for function can not be resolved AND invalid arguments!

 

Hola, Felipe,

About the "function cannot be resolved" problem: Please note that C allows calling undefined functions. C++ will not - you should get the warning right after renaming sample.c to sample.cpp.

About the "invalid arguments": The argument 'a' is a char which is implicitly castable to double, so the call h_function('a') is valid. If you try something not castable to double, you'd get the error. Try replacing that call with h_function("str").

Hope that helps. Thank you for the awareness :)

Best regards,
-- Tomasz Wesołowski

On Fri, Sep 3, 2010 at 1:03 AM, Figuer, Felipe A <Felipe.A.Figuer@xxxxxxxxxx> wrote:

Hi all.  First thanks for your help.

 

Do the “function can not be resolved” and the “invalid arguments”  checkers work?

 

I am trying them in a trivial project having the inclusion for both as: src/*.c

 

The code is quite trivial:

 

Sample.h contents:

 

#ifndef SAMPLE_H_

#define SAMPLE_H_

 

int h_function(double param);

void void_func();

#endif /* SAMPLE_H_ */

Sample.c contents:

 

#include <stdlib.h>

#include "Sample.h"

 

int main(void) {

      return EXIT_SUCCESS + h_function('a') + function_that_does_not();

}

int h_function(double param) {

      return 45;

}

 

void void_func() {

      return;

}

 

I was expecting a warning or something similar for the h_function call (it provides a char when a double is declared as the type parameter).

 

On the other hand as the case of referring an undeclared variable I was expecting a warning or something  like that for the not declared function call function_that_does_not.

 

Am I missing something?

 

Best regards and thanks again,

 

Felipe Antonio Martinez Figueroa.

+52 442 1030500 Ext.1249.

felipe.a.figuer@xxxxxxxxxx

Delphi Electronics & Safety

Software Development Tools & Expert Synergy User & Suggestions Committee Leader

Queretaro Technical Center.

Circuito Palma Cocotera No. 2059.

Fraccionamiento Palmares.

Queretaro, Qro. CP 76127

Mexico.

****************************************************************************************
 
Note:  If the reader of this message is not the intended recipient, or an employee or agent responsible for delivering this message to the intended recipient, you are hereby notified that any dissemination, distribution or copying of this communication is strictly prohibited. If you have received this communication in error, please notify us immediately by replying to the message and deleting it from your computer. Thank you. 
 
****************************************************************************************


_______________________________________________
cdt-dev mailing list
cdt-dev@xxxxxxxxxxx
https://dev.eclipse.org/mailman/listinfo/cdt-dev

 

****************************************************************************************
Note:  If the reader of this message is not the intended recipient, or an employee or agent responsible for delivering this message to the intended recipient, you are hereby notified that any dissemination, distribution or copying of this communication is strictly prohibited. If you have received this communication in error, please notify us immediately by replying to the message and deleting it from your computer. Thank you. 
****************************************************************************************

 

****************************************************************************************

Note:  If the reader of this message is not the intended recipient, or an employee or agent responsible for delivering this message to the intended recipient, you are hereby notified that any dissemination, distribution or copying of this communication is strictly prohibited. If you have received this communication in error, please notify us immediately by replying to the message and deleting it from your computer. Thank you. 

****************************************************************************************

Back to the top