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,
TI C/C++ Compiler Forum ModeratorPlease click Verify Answer on the best reply to your questionThe CCS Youtube Channel has short how-to videosThe Compiler Wiki answers most common questionsTrack an issue with SDOWP. Enter your bug id in the Search box.
In reply to George Mock:
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
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.
In reply to saltan:
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.
You are right. I'm in a wrong way :) I changed all of the "NULL"s with "0" and everything is OK now.
All content and materials on this site are provided "as is". TI and its respective suppliers and providers of content make no representations about the suitability of these materials for any purpose and disclaim all warranties and conditions with regard to these materials, including but not limited to all implied warranties and conditions of merchantability, fitness for a particular purpose, title and non-infringement of any third party intellectual property right. TI and its respective suppliers and providers of content make no representations about the suitability of these materials for any purpose and disclaim all warranties and conditions with respect to these materials. No license, either express or implied, by estoppel or otherwise, is granted by TI. Use of the information on this site may require a license from a third party, or a license from TI.
TI is a global semiconductor design and manufacturing company. Innovate with 100,000+ analog ICs andembedded processors, along with software, tools and the industry’s largest sales/support staff.