Quote:
Originally posted by Skabana159
We were under the impression that C will always start running at main()
|
C programs don't really "start" anywhere. Instead, your C program begins when something outside that program calls one of your functions. By convention, this is typically main(), but that's really decided by the operating system. On a desktop machine, the OS will copy your program off of the disk into RAM and then jump to the address of the program's entry point (i.e. main()). In an embedded system without an operating system, however, the processor simply starts executing code at a certain address when it's turned on. This address is hard-coded and is known as the "reset vector". Typically this reset vector is located near the end of the processor's address space, which means there isn't a lot of room for code. So, what usually happens is that the reset vector is just used to call some other function located somewhere else in memory with more room for code. In IFI's case, the code for _entry() probably gets put at the reset vector, which then calls _startup() which allows IFI to do some housekeeping stuff before it calls main() - they didn't have to use main() but they did just because everyone is used to main() being the entry point for user-supplied code. There's no reason that code running on the PIC would have to have a function named main() at all.
Well this was a nice long winded message that probably isn't all that clear. Let me know though if you'd like me to explain anything better or differently...