POINTERS_EQUAL test won't compile with functions pointers

63 views
Skip to first unread message

Michael DeLibero

unread,
Sep 9, 2015, 6:20:58 PM9/9/15
to cpputest
I am having an issue with using the POINTERS_EQUAL macro with function pointers.

Compiling this test:

#include "CppUTest/TestHarness.h"


void fun(void);

void fun(void)

{

}


TEST_GROUP(PointersEqualTest)

{

};


TEST(PointersEqualTest, NULLS)

{

    POINTERS_EQUAL(NULL,NULL);

}


TEST(PointersEqualTest, PointerToVariableEqual)

{

    int var;

    int* var_ptr;


    var_ptr = &var;

    POINTERS_EQUAL(&var,var_ptr);

}


TEST(PointersEqualTest, FunctionPointerEqual)

{

    void (*funPtr)(void);

    funPtr = fun;


    POINTERS_EQUAL(&fun, funPtr);

}


--------------

Compiling this test gives me:


make -f MakefileCppUTest.mk 

compiling PointersEqualTest.cpp

tests/PointersEqualTest.cpp:31:5: error: cast between pointer-to-function and pointer-to-object is an

      extension [-Werror,-Wpedantic]

    POINTERS_EQUAL(&fun, funPtr);

    ^~~~~~~~~~~~~~~~~~~~~~~~~~~~

/Users/mldelibero/tools/cpputest/include/CppUTest/UtestMacros.h:210:5: note: expanded from macro

      'POINTERS_EQUAL'

    POINTERS_EQUAL_LOCATION((expected), (actual), NULL, __FILE__, __LINE__)

    ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

/Users/mldelibero/tools/cpputest/include/CppUTest/UtestMacros.h:216:51: note: expanded from macro

      'POINTERS_EQUAL_LOCATION'

  { UtestShell::getCurrent()->assertPointersEqual((void *)expected, (void *)actual, text, file, line); }

                                                  ^~~~~~~~~~~~~~~~

tests/PointersEqualTest.cpp:31:5: error: cast between pointer-to-function and pointer-to-object is an

      extension [-Werror,-Wpedantic]

    POINTERS_EQUAL(&fun, funPtr);

    ^~~~~~~~~~~~~~~~~~~~~~~~~~~~

/Users/mldelibero/tools/cpputest/include/CppUTest/UtestMacros.h:210:5: note: expanded from macro

      'POINTERS_EQUAL'

    POINTERS_EQUAL_LOCATION((expected), (actual), NULL, __FILE__, __LINE__)

    ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

/Users/mldelibero/tools/cpputest/include/CppUTest/UtestMacros.h:216:69: note: expanded from macro

      'POINTERS_EQUAL_LOCATION'

  { UtestShell::getCurrent()->assertPointersEqual((void *)expected, (void *)actual, text, file, line); }

                                                                    ^~~~~~~~~~~~~~

2 errors generated.

make: *** [objs/tests/PointersEqualTest.o] Error 1


-----


Has anyone run into this before?

Bas Vodde

unread,
Sep 9, 2015, 10:02:13 PM9/9/15
to cppu...@googlegroups.com

Hi,

Thats why in the recent CppUTest there was an addition of FUNCTIONPOINTERS_EQUAL :)

Please use that one.

Bas

--
You received this message because you are subscribed to the Google Groups "cpputest" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cpputest+u...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Steven Collins

unread,
Sep 9, 2015, 10:30:28 PM9/9/15
to cppu...@googlegroups.com
I believe the answer is contained in the test itself. Notice that when you assign the value of funPtr that you don't say "&fun". In the same way you should say "fun" in the test statement, not "&fun".

--
Message has been deleted

Michael DeLibero

unread,
Sep 10, 2015, 9:13:39 PM9/10/15
to cpputest
Using FUNCTIONPOINTERS_EQUAL solved my problem.

@SPC Thanks for the insight. You are right that I don't specifically need to be that expressive with casting to the function pointer, but my compiler setup with cpputest still does not work with 


POINTERS_EQUAL(funPtr, fun);


As far as I can tell, the compiler is not complaining about my arguments in and of themselves, but in how the cpputest macro deals with them.
Reply all
Reply to author
Forward
0 new messages