Today 20:22
Forum: Proton Plus Compiler v3
Starter: RGV250
Views: 0
Replies: 14
Today 20:03
Forum: Absolute Beginners Section
Starter: Hornett
Views: 0
Replies: 3
Go to last post By: charliecoultas
Today 15:54
Forum: Proton Plus Compiler v3
Starter: BillR
Views: 15995
Replies: 53
Today 04:34
Forum: Projects discussion
Starter: flosigud
Views: 0
Replies: 4
+ Reply to Thread
Results 1 to 4 of 4
  1. #1
    Article Author johngb's Avatar
    Join Date
    Oct 2003
    Posts
    2,055
    Thumbs Up
    Received: 51
    Given: 0
    Total Downloaded
    943.46 MB

    0 Not allowed!

    Default Pre-processor question why does this give me an error

    In my main program early on I have this statement.

    Code:
    $define OSERROR_HANDLER DefaultErrorHandler
    Later on in main prog file I have

    Code:
    $ifdef OSERROR_HANDLER
        $defeval OSEVENTS_COUNT $eval OSEVENTS_COUNT + 1 ' Extend events count by 1 event ECBs
        Include "P24RTOSErrors.inc"
    $endif
    In P24RTOSErrors.inc I have

    Code:
    $if OSERROR_HANDLER = DefaultErrorHandler
    
    DefaultErrorHandler:
    
    
    Return
    
    $endif
    The pre-processor reports error on the line indicated in red

    "unrecognised or incorrect operator syntax!"
    JohnB

  2. #2
    Developer Les's Avatar
    Join Date
    Feb 2002
    Posts
    3,101
    Thumbs Up
    Received: 203
    Given: 70
    Total Downloaded
    1.41 GB

    0 Not allowed!

    Default Re: Pre-processor question why does this give me an error

    A label is not a preprocessor directive John, so it does not see it. $if and $ifdef and $indef etc, will only work with texts are are created with $define
    Also creating a $define that will later be a label of the same name will cause all sorts of problems because the texts will be different.
    For more example programs for Proton and Proton24 or updates, please visit: Proton WIKI or Proton Files

  3. #3
    Article Author johngb's Avatar
    Join Date
    Oct 2003
    Posts
    2,055
    Thumbs Up
    Received: 51
    Given: 0
    Total Downloaded
    943.46 MB

    0 Not allowed!

    Default Re: Pre-processor question why does this give me an error

    I think you missed what I am trying to do...

    Code:
    $define OSERROR_HANDLER DefaultErrorHandler   '  OSERROR_HANDLER now holds the string value 'DefaultErrorHandler' whis is the name of the procedure which will handler the error.
    
    $ifdef OSERROR_HANDLER
        $defeval OSEVENTS_COUNT $eval OSEVENTS_COUNT + 1   ' Extend events count by 1 event ECBs
        Include "P24RTOSErrors.inc"
    $endif
    Here is an example of how I how I use the above defines....

    Code:
    '---------------------------------------------------------------------------------------------------
    ' Creates a task - TaskAddr is the address(Label) of the task and priority is the priority level
    ' Returns with the Index (TaskID) of the entry into the Task Control block or OSNO_TASK if it fails.
    
    
        Proc OSCreateTask(ByRef TaskAddr As Dword, Priority As Word, Start As Word), Word
          Result = GetTaskID()                            ' Get new TaskID
          If Result <> OSNO_TASK Then 
            LoadTask(Result, TaskAddr, Priority, Start)   ' Load up TCB
        $ifdef OSERROR_HANDLER
          Else
            LastError = OSTASK_CREATE_ERROR     
            OSERROR_HANDLER()                  ' Call the Assigned error handler
        $endif
          EndIf
        EndProc
    Here the pre-processor should have substituted OSERROR_HANDLER with the string assigned to OSERROR_HANDLER at the top of the code in the initial $define statement. If the user wanted to have his own error handler he would set OSERROR_HANDLER to the name of his error handler Procedure.

    In the Include file I provide a default handler which users can utilise.

    Code:
    $If OSERROR_HANDLER = DefaultErrorHandler
    
    Proc DefaultErrorHandler()
      HRSOut "Source Code ", Dec LastError.HighByte, " Reason Code ". Dec LastError.LowByte
    endProc
    
    $endif
    What I am trying to do with the pre-processor here is to include the Default error handler code if the OSERROR_HANDLER text contains DefaultErrorHandler. Since the preprocessor is simply a string handler I cannot see how it matters whether it is a label or not.
    JohnB

  4. #4
    Article Author johngb's Avatar
    Join Date
    Oct 2003
    Posts
    2,055
    Thumbs Up
    Received: 51
    Given: 0
    Total Downloaded
    943.46 MB

    0 Not allowed!

    Default Re: Pre-processor question why does this give me an error

    Also creating a $define that will later be a label of the same name will cause all sorts of problems because the texts will be different.
    I have been using the $define as explained above and it does work. The only issue I had was when I tried to use its value in a conditional ($if).
    Are you saying that I shouldn't use a define to reference a Procedure or Subroutine. I did this successfully in my original RTOS again without any issues I was aware of.
    JohnB

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

     

Similar Threads

  1. Local Variables: a pre-processor question
    By AlbertoFS in forum Proton Plus Compiler v3
    Replies: 0
    Last Post: 8th June 2017, 19:43
  2. Pre-processor question
    By joesaliba in forum Proton Plus Compiler v3
    Replies: 11
    Last Post: 10th March 2017, 18:49
  3. Pre-processor issue??
    By johngb in forum Proton Plus Compiler v3
    Replies: 2
    Last Post: 29th September 2012, 11:01
  4. pre processor
    By ADLIN SYSTEMS in forum The Lounge
    Replies: 0
    Last Post: 17th September 2011, 19:53
  5. Pre-Processor Question
    By johngb in forum Proton Plus Compiler v3
    Replies: 0
    Last Post: 4th July 2011, 19:28

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts