Issues using C++ headers

Technical questions regarding the XTC tools and programming with XMOS.
rhind
Junior Member
Posts: 6
Joined: Fri Jun 17, 2011 9:31 am

Issues using C++ headers

Post by rhind »

I have a few issues with C++ headers in 11.2.1 from .cpp files:

1) #include <algorithm> / <cstddef> gives a warning in the editor (shown in the gutter) saying its an unresolved include although the project builds fine.

2) If <xs1.h> is included before <algorithm> then you can't include <algorithm> as you get an error about a re-declaration of clock_t

Neither are major as I can work around both but the first is just an annoyance in the editor and for the second, it means re-defining items from xs1.h myself rather than using it (for defines such as XS1_TIMER_HZ etc).

Cheers

Russell


richard
Respected Member
Posts: 318
Joined: Tue Dec 15, 2009 12:46 am

Post by richard »

rhind wrote:2) If <xs1.h> is included before <algorithm> then you can't include <algorithm> as you get an error about a re-declaration of clock_t

Neither are major as I can work around both but the first is just an annoyance in the editor and for the second, it means re-defining items from xs1.h myself rather than using it (for defines such as XS1_TIMER_HZ etc).
Problem 2) is hard to avoid since xs1.h defines the clock type which clashes with the declaration of the clock() function in clock.h included indirectly from <algorithm>. Renaming either of these isn't really an option (clock() is part of the C standard and renaming the clock type would break lots of XC code).

Another workaround is as follows:
#define clock __clock
#include <xs1.h>
#undef clock
#include <algorithm>
This avoids the need to copy definitions out of xs1.h.
rhind
Junior Member
Posts: 6
Joined: Fri Jun 17, 2011 9:31 am

Post by rhind »

#define clock __clock
#include <xs1.h>
#undef clock
#include <algorithm>
Thanks, I may try this but for now I think its easier to duplicate the stuff I need out of xs1.h in to my own header that doesn't declare the clock stuff.

A shame the XC types couldn't be prefixed with xc_ or something to try and avoid conflicts with standard C/C++ stuff.

Cheers

Russell
User avatar
segher
XCore Expert
Posts: 844
Joined: Sun Jul 11, 2010 1:31 am

Post by segher »

rhind wrote:A shame the XC types couldn't be prefixed with xc_ or something to try and avoid conflicts with standard C/C++ stuff.
There aren't any conflicts with standard C stuff.