News:

PROTON pic BASIC Compilers for PIC, PIC24, dsPIC33

Main Menu

Is ++ ok to use?

Started by TimB, Dec 01, 2025, 09:31 PM

Previous topic - Next topic

TimB


I have seen in code Les posted the use of Var++ eg post inc the variable. Its not listed in the manual. Can I use it?

Thanks

Tim

charliecoutas

Yes Tim, it's in the manual. Search for ++

Charlie

CPR

Quote from: TimB on Dec 01, 2025, 09:31 PMI have seen in code Les posted the use of Var++ eg post inc the variable. Its not listed in the manual. Can I use it?

Thanks

Tim

Alternatively just try it and see what gives?

TimB


Thanks

I did look in the manual but obviously not properly

 

Stephen Moss

#4
Quote from: TimB on Dec 01, 2025, 09:31 PMI have seen in code Les posted the use of Var++ eg post inc the variable. Its not listed in the manual. Can I use it?

Thanks

Tim
If you are trying to use it to increment a regular variable, then as far as I know you can't (or at least it is undocumented).
I only recall seeing the use of ++ and -- in the manual in relation to Pre or Post incrementing and decrementing an address when using the Ptr and cPrt commands to read/Write RAM/Flash memory locations.

TimB


Thanks Stephen

Yes I figured that out when I tried to use it not in relation to  read/Write RAM/Flash memory locations....

top204

#6
The --Var or ++Var or Var-- or Var++ are only used in the Ptr and cPtr commands, because there was no other way to add a mechanism for pre and post address increments and decrements. So I used the same method as some of the mnemonics. i.e. 'Movwi INDF0++' or Mov.w [W15++],W0 etc...

One of my pet hates is when they are used in the C and C++ language, because they are messy, and are misused in so many places, making the code actually more difficult to read and understand what the device should be doing. The same with 'Var += Var' or 'Var /= Var' etc... Totally dreadful and sloppy IMO.

But when users are continually copying and pasting, as in C and C++, it does not really matter if they know what is happening in the code or device. :-)