Shop OBEX P1 Docs P2 Docs Learn Events
SimpleIDE programming question — Parallax Forums

SimpleIDE programming question

NWCCTVNWCCTV Posts: 3,629
edited 2013-10-14 11:56 in Propeller 1
This may seem a bit out there but I have a question about the SimpleIDE Library and header files. Is it possible to use a completed C project and save the C file as a Header? In other words, kind of like how SPIN handles Objects. So, could I, as an example, save the libCompass3d project as a .h Header file to be used in another project?

Comments

  • jazzedjazzed Posts: 11,803
    edited 2013-10-11 22:22
    You could write all your code as a header file, but the main function should be something unique if you wanted to share it.

    C++ makes it easier because the scope of symbols can be limited to classes to avoid a "global catastrophe" of functions and variables, etc....
  • NWCCTVNWCCTV Posts: 3,629
    edited 2013-10-11 23:06
    the main function should be something unique if you wanted to share it
    Not sure what you mean here.
  • jazzedjazzed Posts: 11,803
    edited 2013-10-14 09:56
    NWCCTV wrote: »
    Not sure what you mean here.

    For every C program, there is a function called "main(...)" that serves as the start point of the program. If you create .h "header libraries", the function "main(...)" must not be included in the header.

    There are many other considerations. An experienced C programmer could deal with them, but it can still be frustrating.
  • NWCCTVNWCCTV Posts: 3,629
    edited 2013-10-14 11:56
    Got it. Thanks for the help.
  • Heater.Heater. Posts: 21,230
    edited 2013-10-14 11:56
    If you have a program that runs nicely by itself it will surely have a "main" function.
    Let's say you have two such programs and you want to combine them into a single application.
    That won't fly as the C compiler want's to have only one "main" as that is where everything is started from and you can't have two starting points.

    What to do?

    Change the names of those "main" functions to something else reflecting whatever those program do.

    Create a new file with a "main" that now starts those two new functions. Perhaps one is a started in a new COG and the other is called directly to run in the current cog.

    How you get those two programs now running together concurrently to communicate with each other is another matter.
Sign In or Register to comment.