Changing file from .c to .xc causes mismatches with previous Topic is solved

If you have a simple question and just want an answer.
User avatar
aclassifier
XCore Expert
Posts: 512
Joined: Wed Apr 25, 2012 8:52 pm

Changing file from .c to .xc causes mismatches with previous

Post by aclassifier »

When I rename the file that contains main from .c to .xc I get errors on drawBitmap, print and println with first three "found" messages, then three "previous" messages and then three "Type of symbol ... has mismatch with previous definition" messages. All three functions are in a .c file.

Everything compiled and ran before the rename. I can take it back and it works. I use module_i2c_master and module_random. For the random I had to remove an & for random generator call for the .xc file.

The API of the three files (there are many more in that file) are textually equal. I get search hits on both. I thought that there was a name crash, but when I renamed it didn't help. One goes like this:

extern void drawBitmap (int16_t x, int16_t y, const uint8_t *bitmap, int16_t w, int16_t h, uint16_t color);

I thought that the parameter types were renamed by other typedefs of defines for the xc path, but then I assume the compiler would have complained about that.

I cannot double-click on the error messages to get the lines up. But the lines are visible with a small arrow in the code.

After two days of research on this I am blank!

--
Øyvind Teig
Trondheim (Norway)
https://www.teigfam.net/oyvind/home/
View Solution
srinie
XCore Addict
Posts: 158
Joined: Thu Mar 20, 2014 8:04 am

Post by srinie »

Hi,

For 'mis-match with previous definition', you can include "xccompat.h"; it contains some xC typedefs compatible to C;

eg., void fnAbc(REFERENCE_PARAM(int a))   ==> void fnAbc(int &a) in xC; void fnAbc(int *a) in C;

For pointer variables, you may use 'unsafe'; (int *a) ==> (int * unsafe a)

 

https://www.xmos.com/download/public/Ca ... 8X7665F%29...

 

User avatar
davelacey
Experienced Member
Posts: 104
Joined: Fri Dec 11, 2009 8:29 pm

Post by davelacey »

In xC, pointers are safe pointers (see the programming guide, section 5.2). This means a prototype like:

extern void f(int *p);

in xC will assume that p is a safe pointer (with bounds checking). This is incompatible with plain C pointers.

To use a C function from xC, the best way is to wrap the protoype in an extern "C" block e.g.

extern "C" {

   void f(int *p)

};

This will tell the xC compiler that the external function is a C function and any pointers in its prototype are plain C pointers (equivalent to "unsafe" pointers in the xC world).