SimpleIDE Library Questions. "Propeller C Library Studies"

I'm trying to follow the "Propeller C Library Studies" tutorial. I was wondering if you guys could answer a few questions.
learn.parallax.com/tutorials/language/propeller-c/propeller-c-library-studies


I understand why the libawesome.c file has #include "simpletools.h". It needs it for the print function.

I don't understand why the awesome.h file needs #include "simpletools.h", since it doesn't actually use the print function.

I also don't understand why the awesome.c file does not need the #include "simpletools.h", since it does actually use the print function.

The awesome.c file has #include "awesome.h" at the top. Does the awesome.c file get its print function from the simpletools.h include, in the awesome.h header file?

Wow, i have reread this a hand full of times, and my questions don't seem real clear. I can't seem to come up with a better way to ask them. Hopefully someone will figure out what Im asking.
Thanks
Shawn

Comments

  • 4 Comments sorted by Date Added Votes
  • Yes.
    Tom
  • JonMJonM Posts: 236
    edited September 4 Vote Up0Vote Down

    Usually you will add the required include files in the header file rather than in the ".c" since the header might be used in other places and to keep the main source file cleaner. So, adding "awesome.h" in "awesome.c" will bring over the "#include" directives from "awesome.h" thus you do not have to include them into "awesome.c".

    Technically since "awesome.h" is included in "libawesome.c", you do not need to add the "simpletools.h" directive at the top of the file and it should be picked up from "awesome.h".
  • Thanks for the confirmation.

    I'm having a hard time wrapping my head around include files. I want to try and compare the use of the include files in C, to the use of objects in Spin. In spin you can open up the object file and look though the program and see all the functions, and how to use them. In C it seems to be a bit harder. For instance, a lot of the examples on the learn site use simpletools.h. I opened the simpletools.h file and looked for the fucnction print(), I could not find it. I'm not understanding something. I was looking for a simpletools.c, but I've come to the conclusion that it doesn't exist. Simpletools.h must be a header file that pulls together a number of other actual c files. So whats the easiest way to find what file a specific function actually lives in? In this case the print() function.
    /*
    Hello Message.c

    Display a hello message in the serial terminal.

    http://learn.parallax.com/propeller-c-start-simple/simple-hello-message
    */

    #include "simpletools.h" // Include simpletools header

    int main() // main function
    {
    print("Hello!!!"); // Display a message
    }

    print("Hello!!!");
    What .c file does this actually come from?

    For instance, in spin, there is a parallax serial terminal object. When the object is opened, I can see all the different functions that can be called. Like changing the baud rate for transmitting and receiving. Maybe I cannot compare include files and object files.


  • Ah, I would suggest a good course or book in "C" to assist in your understanding of the language.

    However, a ".h" does not always have to have a provided ".c" file. The ".h" file could be used to just add the interfaces to functions that are defined elsewhere. This way, as in the case of "simpletool.h", you just have to add one file and not the entire list as in "simpletool.h". The actual definition of the a function might be defined in a compiled linked library and the interface is provided in a ".h". All you need to really know is how to call the function in your code and not worry about the inner workings of the actual function. There are tools to look deeper at a compiled linked library such as gdb with gcc but that is a bit advanced.

    In simpletools.h there is a number of "#include" entries that bring in code from various sources.
    #include <propeller.h>
    #include "simpletext.h"
    #include <driver.h>
    #include <stdio.h>
    #include <stdlib.h>
    #include <string.h>
    #include <cog.h>
    #include <ctype.h>
    #include <unistd.h>
    #include <sys/stat.h>
    #include <dirent.h>
    #include <sys/sd.h>
    #include <math.h>
    #include "simplei2c.h"
    

    You will find the "print" definition in "simpletext.h".
Sign In or Register to comment.