# Check if task exists in Not eXactly C

Is there a way to check if a task, function or variable exists in Not eXactly C?

I know that in PHP you can use isset() to check if a variable exists and function_exists() to do the same for a function, but is there a way to do that in NXC?

I am specifically interested in checking whether a task exists or it is alive.

As NXC is a compiled language, I would assume calling a non-existent function or accessing a non-existent variable would throw a syntax error during compilation as it does in other compiled languages I have used.

Conversely, in interpreted languages like PHP and Python you can often call or access things that don't exist without creating an issue until that actual call or access happens - hence the need for method's like isset() and function_exists() in PHP.

Edit: Looking at the Tasks docs it seems that a "task" is similar to a function in that it is defined in the source code, versus being created dynamically at run-time. I expect if you write something like: Precedes(non_existent_task_name); ("Precedes" being a function to start tasks), and try to compile you would trigger the same sort of syntax error as you would if you did something like: call_of_non_existent_function();

• This seems right. I haven't worked with NXC, but the task part of the question seems like something that could be checked. A task may or may not be alive and that's not a compiler semantics. Is there a way to check that? – Shahbaz Dec 13 '12 at 10:31
• @Shahbaz I've had a browse over the docs and have updated my answer to cover the "exists" for tasks - tasks appear to be defined before compilation so should have the same errors as functions. The "alive" component of the answer will require someone a bit more familiar with NXC syntax, but would usually be done (in the absence of API helpers) with a flag - just before exiting the task could set a global variable to indicate that the task has stopped itself. – thisismyrobot Dec 15 '12 at 0:23

No, it seems that there's no such possibility, because there's no method in the manual.

• if it's a small snippet in the manual, you can quote it here to prevent link rot and so the whole relevant information is contained in the answer. – ThomasH Dec 13 '12 at 7:56
• @ThomasH: There's no such snippet, it's just not there in the API. – looper Dec 13 '12 at 7:58
• I get you, in that case maybe just mention that the manual lists no such function. – ThomasH Dec 13 '12 at 8:11