Just for info Expander Function

Beta Testing discussion on mikroC PRO for dsPIC30/33 and PIC24.
Post Reply
Author
Message
Ptech
Posts: 83
Joined: 20 Jan 2008 16:44

Just for info Expander Function

#1 Post by Ptech » 11 Jan 2010 21:49

Hi.

The Compiler does not complain or show any error mistyping when typing

Expander_Write_PortB,(0,16); <---- extra comma after PortB

The function is not working with the comma.


//P

Sobrietytest
Posts: 619
Joined: 05 Jul 2008 06:05
Location: Thailand

#2 Post by Sobrietytest » 13 Jan 2010 07:30

The old compiler doesn't catch it either. I think you have to remember that the compiler can help with syntax but the main responsibility is with the programmer to get it right (and that's the same with any programming language).

There are so many instances where comma seperation is legal, it would be very difficult for the compiler to weed out the illegal ones.

User avatar
srdjan
mikroElektronika team
Posts: 1552
Joined: 28 Dec 2005 12:47
Location: Serbia

Re: Just for info Expander Function

#3 Post by srdjan » 16 Jan 2010 15:29

Hi,
Ptech wrote:Hi.

The Compiler does not complain or show any error mistyping when typing

Expander_Write_PortB,(0,16); <---- extra comma after PortB

The function is not working with the comma.


//P
mikroC for dsPIC help wrote: One of the specifics of C is that it allows using of comma as a sequence operator to form so-called comma expressions or sequences. Comma expression is a comma-delimited list of expressions – it is formally treated as a single expression so it can be used in places where an expression is expected. The following sequence:

Code: Select all

expression_1, expression_2;
results in the left-to-right evaluation of each expression, with the value and type of expression_2 giving the result of the whole expression. Result of expression_1 is discarded.
So,

Code: Select all

Expander_Write_PortB,(0,16);
goes to:

Code: Select all

Expander_Write_PortB, // expression #1, legal, Expander_Write_PortB represent pointer to a function
( // denotes start of expression #2
0, // expression #3, legal, constant expression
16 // expression #4, legal, constant expression
) // denotes end of expression #2
; 
This is the same as:

Code: Select all

Expander_Write_PortB;
0;
16;
Now, it should be clear why this translates with no errors and results in no code generated for specified code line.

Post Reply

Return to “mikroC PRO for dsPIC30/33 and PIC24 Beta Testing”