Nicholas Reiser
Nicholas Reiser

Reputation: 21

What is "<:" in C?

I'm troubleshooting some simple tutorial code for XMOS processors and I've come across an operator that I've never seen before in C. What does <: do? As it is used here, it appears to set a variable high or low, but why not just use =?

void flashing_led_task1(port p,int delay_in_ms){
    while(1){
        p<:0;
        delay_milliseconds(delay_in_ms);
        p<:1;
        delay_milliseconds(delay_in_ms);
    }
}

This is just a generic question that I could not find googling or searching stack exchange.

Upvotes: 1

Views: 107

Answers (1)

Jonathan Leffler
Jonathan Leffler

Reputation: 754080

In Standard C, the <: and :> symbols are digraphs. Except for spelling, <: is equivalent to [ and :> is equivalent to ].

However, when those symbols are translated in your code (and the code reformatted for readability, including adding a space between void and the function name, and between port and p, and between int and delay_in_ms), you end up with:

void flashing_led_task1(port p, int delay_in_ms)
{
    while (1)
    {
        p[0;
        delay_milliseconds(delay_in_ms);
        p[1;
        delay_milliseconds(delay_in_ms);
    }
}

And that doesn't make much sense. So, you may have to look hard at the manual for the C compiler on your system to find out what it means. Or it might just be that your copy'n'paste operations, which (I hypothesize) omitted some spaces, also omitted the :> symbols or other key bits of the code fragment.

With the hint about XC from Eugene Sh., p13 of the XC Manual (the start of chapter 2) has a diagram with:

  • <: used for output
  • :> used for input

The code on p14 shows these operators in use.

XC is not the same as C, though it is closely related.

Upvotes: 6

Related Questions