Products > Programming

How is this programmed?

(1/3) > >>

Ground_Loop:
I have a Arduino sketch that references functions in a manner that looks like members of a structure.  I'd like to do the same for a PIC project. For instance, in the Arduino sketch there are numerous functions defined for the LCD display control such as Set_Cursor(x,y), blink(), clear(), etc. defined in the usual manner in header and source files.  However, when used in the main sketch they are referenced similar to structure members as LCD.Set_Cursor(x,y) or LCD.clear(). I don't see in any of the files how the "LCD." portion of the reference is setup and would really like to do it in other programs on other platforms.  Apologies if this is a confusing description.

WattsThat:
No specifics on devices/compilers/environments so it’s hard answer the question but...

LCD is instantiated somewhere in the Arduino code, you just haven’t looked in the right place.

The Arduino environment use the GCC compilers which are C++, in the PIC world, the 8 bit compilers don’t do C++. So if it’s an 8bit PIC, you’re barking up the wrong tree, can’t do it.

greenpossum:
The Arduino compiler actually is a C++ compiler and what you have described are member functions, and are referred to similar to storage members but of course there is only one instance of the function. The object which the function is invoked on is implementation-wise handled like a hidden argument.

To do the same on the PIC you'd need a C++ compiler, otherwise you'd have to emulate it in C, say by passing a pointer to the object (struct) as the first argument by convention. That's what's done in languages like Python.

Ground_Loop:
Thanks.  I had a suspicion it was a C++ thing.  My question is answered.
BTW, my other project is on a PIC24 using XC16.  I just thought the technique was cool and wanted to replicate it.  Not really a pressing need though.

Mechatrommer:

--- Quote from: Ground_Loop on April 11, 2020, 12:33:02 am ---I just thought the technique was cool and wanted to replicate it.

--- End quote ---
its called OOP (Object Oriented Programming) its been there for ages. as long as i can remember, C++ is the one who started it...

Navigation

[0] Message Index

[#] Next page

There was an error while thanking
Thanking...
Go to full version
Powered by SMFPacks Advanced Attachments Uploader Mod