embedded c code on c compiler

This is a discussion on embedded c code on c compiler within the C Programming forums, part of the General Programming Boards category; Can embedded c code be compiled on a c compiler.if yes how, if no why not....

  1. #1
    Registered User
    Join Date
    Nov 2007
    Posts
    11

    Question embedded c code on c compiler



    Can embedded c code be compiled on a c compiler.if yes how, if no why not.

  2. #2
    Deathray Engineer MacGyver's Avatar
    Join Date
    Mar 2007
    Posts
    3,211
    If it can't be compiled using a C compiler, how do you propose to compile it? lol

  3. #3
    Registered User
    Join Date
    Oct 2001
    Posts
    2,129
    If you have the right compiler. Embedded code is often different from ANSI/ISO code, so you would probably need a specialized compiler.

    But how could you compile C code without a C compiler?

    So yes and no.

  4. #4
    Registered User
    Join Date
    Nov 2007
    Posts
    11

    Thumbs down re:embedded c on c compiler

    My view is that in keil for example it generates the back end code in .a51 format.

    In the same way if we can create the hardware specifications as a different file and combine it link it with the functionality file on any c compiler i think we should be able to do that.

    Am i right or wrong?

    pls guide.

  5. #5
    Deathray Engineer MacGyver's Avatar
    Join Date
    Mar 2007
    Posts
    3,211
    Are you trying to describe cross compilation?

  6. #6
    Registered User
    Join Date
    Nov 2007
    Posts
    11

    Question

    NO i am not trying to describe cross compilation,
    i am trying to run a embedded c code (for ex that runs on keil for a specific hardware req )
    on a normal c compiler such as turbo c .(with 2 files
    one for hardware specs and other for functionality and link them later.)

  7. #7
    Registered User
    Join Date
    Oct 2001
    Posts
    2,129
    What architecture or system or target you can compile for is entirely compiler-dependant.

    I don't think that Turbo C supports anything other than the x86 architecture. I also don't think that the keil compiler compiles programs for anything other than the respective embedded platforms that are listed on its website. (just from a quick google)

    GCC supports a wide range of targets that you might be able to use. But such compatibility is highly compiler-specific.

    You could perhaps use the IDE from one compiler and easily reconfigure it to run a different compiler, but that's not really using a different compiler, although it might seem like it is.

    Your best bet is probably to contact the compiler vendor, but I wouldn't get my hopes up.
    Last edited by robwhit; 11-28-2007 at 05:45 PM.

  8. #8
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,540
    > i am trying to run a embedded c code (for ex that runs on keil for a specific hardware req )
    > on a normal c compiler such as turbo c .(with 2 files
    Aside from calling TurboC a normal C compiler, this is perfectly possible (I do it all the time). Step 1 is get a better compiler.

    90% of the code doesn't (or shouldn't) give a hoot what the hardware is, so the host is a perfect place to
    - debug all the functionality.
    - get a pretty good idea of what the memory space usage is likely to be.
    - get some idea of what the performance is likely to be (eventually).

    The real trick is how you decide to "virtualise" your target hardware on your host development platform to give you what you want. To begin with, you make sure that anything which interacts with the target hardware or the target OS (if you have one) has an API wrapped around it.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  9. #9
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    An "a51" file, I suppose means that this code is intended for a 8051 processor, which is essentially a 8-bit processor with some 16-bit capabilities.

    This isn't that far off from a DOS compiler, but as Salem says, some of your code is probably directly hardware related, and other code may make use of some compiler specific extensions [which is not unique for embedded, but it's more likely to happen in "system specific code", rather than generic code that works on "anything"]. These things may show themselves in two ways:
    1. Compiler errors when using compiler-specific extensions.
    2. Weird behaviour and crashing, where the system is accessing hardware that doesn't exist [or at least isn't located in the same place] on the "new" platform.

    I don't particularly like the term "embedded C", but prefer the term "C written for embedded systems" - the difference here is that "Embedded C" implies that the C language itself is different in an embedded system - I strive to write my embedded code with ISO/ANSI compliance whenever possible. There are of course exceptions [you can't always acces hardware resources wihtout breaking standards, because the standard stays away from hardware specifics so much that many hardware specifics actually break the standard].

    But yes, you should be able to compile MOST code for embedded systems with a standard C compiler.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. making programms faster
    By deian in forum C Programming
    Replies: 23
    Last Post: 10-09-2004, 12:19 AM
  2. Compiler or code error?
    By Hunter2 in forum Windows Programming
    Replies: 2
    Last Post: 08-03-2003, 05:59 PM
  3. << !! Posting Code? Read this First !! >>
    By kermi3 in forum Windows Programming
    Replies: 0
    Last Post: 10-14-2002, 01:29 PM
  4. << !! Posting Code? Read this First !! >>
    By biosx in forum C++ Programming
    Replies: 1
    Last Post: 03-20-2002, 11:51 AM
  5. Bad code or bad compiler?
    By musayume in forum C Programming
    Replies: 3
    Last Post: 10-22-2001, 09:08 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21