Calling subs / functions with as a different variable type?

Coding and general discussion relating to the compiler

Moderators: David Barker, Jerry Messina

Post Reply
SHughes_Fusion
Posts: 219
Joined: Wed Sep 11, 2013 1:27 pm
Location: Chesterfield

Calling subs / functions with as a different variable type?

Post by SHughes_Fusion » Thu May 08, 2014 11:01 am

Is there any way to call a sub or function with a number, but to have the compiler treat that number as a different type?

To try and explain more clearly, I store a value in the internal EEPROM which records the pointer to the next free location in an external EPROM.

In my main program I have a Word variable which stores this value during normal program operation but to 'proof' the program against power-cuts, each time I write something to the external EEPROM I update the stored value in EEPROM.

The issue I have is that I want a 'ClearLog' sub which will reset various things in the log 'header', including setting the write pointer to zero. However, if I do EE.Write(Joint_Pointer, 0) this will only write a byte. Is there a way - other than declaring a temporary Word variable - I can send 0 as a Word rather than a byte?

Jerry Messina
Swordfish Developer
Posts: 1473
Joined: Fri Jan 30, 2009 6:27 pm
Location: US

Re: Calling subs / functions with as a different variable ty

Post by Jerry Messina » Thu May 08, 2014 12:28 pm

You could cast it to a different type

Code: Select all

ee.write(joint_pointer, word(0))
or use the word write routine directly

Code: Select all

ee.writeword(joint_pointer, 0)

SHughes_Fusion
Posts: 219
Joined: Wed Sep 11, 2013 1:27 pm
Location: Chesterfield

Re: Calling subs / functions with as a different variable ty

Post by SHughes_Fusion » Thu May 08, 2014 12:41 pm

Thanks, Jerry, Word(0) is what I was looking for - didn't know you could do this. I've used .AsWord for variables but wasn't aware of this.

Post Reply