ROBOTC: Why do #pragma config() preprocessor directives have to be the first lines of the source file?

782 views Asked by At

I'm a tutor for an undergrad class in robotics, and we use robotC (for NXT robotics, version 4.50) as the platform of choice. A strange quirk in robotC that I've noticed is that, for some reason, #pragma config preprocessor directives only work when they are the first lines of the program.

#pragma config(Sensor, S1, touch, SensorTouch)
//comment
#pragma config(Sensor, S2, touch2, SensorTouch)

task main()
{
    while(true){
        nxtDisplayTextLine(0,"%i",SensorValue(touch));
        nxtDisplayTextLine(1,"%i",SensorValue(touch2));
    }
}

When I run this simple program, I get the following compilation errors:

**Error**:'#pragma config(...)' must be first lines of source file
**Error**:Undefined variable 'touch2'. 'short' assumed.

What is the reason for that first error? I can't find anything on the documentation listing a reason why #pragma config() has to be the first lines of the source file, just that it has to be.

EDIT: To clarify. I understand that the error is caused by having the //comment on the second line of the program, as #pragma config() lines have to be the first line(s) of the program. I'm wondering why #pragma config lines HAVE to be the first lines.

1

There are 1 answers

2
Matthew On

I'm not sure on the credibility of it, but I have found a ROBOTC guide from Penn State Abington. The guide mentions that the #pragma statements must be the first few lines. It goes on later to say that they even have to be before any comments. So the problem that is occurring here is caused by the

//comment

on the second line of your code.