This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

CCS 5 or CCS 4 (Doesn't matter) Embedded C++ Compiler errors

Dear All,

I want to transfer a C code to C++ so I used "Embedded C++" option in CCS5. Everything works fine up to now. But One of the C file gives too many errors. Please see the following

 

1. Imagine a .C file can be compiled with no warning or error in CCS5 or CCS4 with its standart C compiler. 

2. When I changed the Language options to "Embeded C++"  the same file gives too many errors like below

    a value of type "void *" cannot be assigned to an entity of type "tcp_pcb * xxx

   argument of type "void *" is incompatible with parameter of type "err_t(*)(void *, tcp_pcb *, u16_t)"

3. I looked the errors in detail and see it is just the NULL pointer gives all of these errors. For example;

   struct tcp_pcb *TelnetPCB;

  TelnetPCB = NULL;   // This gives   a value of type "void *" cannot be assigned to an entity of type "tcp_pcb * xxx

   tcp_recv(pcb, NULL); // This gives argument of type "void *" is incompatible with parameter of type "err_t(*)(void *, tcp_pcb *, u16_t)"

  

4. I think "embedded C++" does not allow to assign a NULL pointer to a typed pointer or a function pointer.

 

5. I thought that There is a choice on compiler options like "Do not restrict NULL pointer assignments" but there is nothing similar and I think I have to typecast all of the NULL assignments in my code and the code will have a very bad style. If I do the below everything is work fine but please think the function pointers I have to use with ethernet applications they are too long for typecasting :) 

 

   struct tcp_pcb *TelnetPCB;

  TelnetPCB =  (struct tcp_pcb *)NULL;   // THIS IS OK

 

 

6. Is there any way to say the compiler do not bother NULL assignments ??? 

 

waiting for your urgent replies



 


 

 

 

  • You must be using your own definition of NULL, and not one from a system header file such as <stdlib.h>.  Further, that definition must look something like ...

    #define NULL ((void *) 0)

    Either change the definition of NULL to 

    #define NULL 0

    or get it from <stdlib.h>

    Thanks and regards,

    -George

  • Dear George

    Thanks for your consider. I tried your suggestion but problems are continue.

    You mean I must define my own NULL definitions for everything and also for  function pointers 

     

    You may know Lwip TCP stack coming with CCS5 and when I want to shutdown something with this library,I have to use a NULL function pointer like below

    tcp_sent(pcb, NULL)

     

    But if you look at the definition of tcp_sent you will see that the second parameter is a function pointer

    void  tcp_sent    (struct tcp_pcb *pcb, 

                                   err_t (* sent)(void *arg, struct tcp_pcb *tpcb, u16_t len));

     

     

    In embedded c++   tcp_sent(pcb, NULL) ==> gives "can not assign a NULL error." I may solve this defining a NULL function pointer I think 

    but as you know defining a function pointer is very hard topic of C and plus there are more than 8 function like tcp_sent gets a function parameter.

    your suggestion is also for function pointers ??? or you gave me a general c++ suggestion that I should use my own NULL pointer.

     

     

     

  • Stroustrup prefers to use 0 over NULL.  See http://www2.research.att.com/~bs/bs_faq2.html#null .  At any rate, you're going about this the wrong way.  No one recommends that you define a NULL of the exact type required for all the types that need it.

    Thanks and regards,

    -George

  • Thanks george, 

    You are right. I'm in a wrong way :) I changed all of the "NULL"s with "0" and everything is OK now. 

     

    Thanks again. 

    Best regards