Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

Static linking and Compliers

Options
  • 02-06-2003 1:52pm
    #1
    Closed Accounts Posts: 423 ✭✭


    Hiyas - A quick query - when compling staticly, how do, or do they at all, compilers optimise the code. Will they only bring only code from the library that is pertainant (sp?) to the application or are they in general lazy and bring everything in the library into the application.
    I guess what I'm trying to say is: do compilers specialise the library with respect to the "client" application.

    Any ideas appreciated! :)

    Dizz


Comments

  • Closed Accounts Posts: 423 ✭✭Dizz


    Wooooops!
    /me had too much last night
    Just realsing now what I've asked is crap!

    Put on your ignore caps people!

    Dizz


  • Closed Accounts Posts: 1,719 ✭✭✭Ruaidhri


    i dunno..it's always bugged me.
    speaking about java(specifically) i always presumed that an import statement like import java.io.* would only import the specifiy classes referenced in the code. of course i'm stil not sure,and a compiler is still a little complex for me to tackle.

    it would be intresting to know..it would help me to write more stremlined code.

    it this what you were after?


  • Closed Accounts Posts: 423 ✭✭Dizz


    In the case of Java, Java will only use the classes that it needs so even if you had the decl. import java.io.* it (the compiler) won't go referencing classes that are not referenced either directly or indirectly. If you like you could say that Java's compiling granularity is to the class level.

    Where it differs for me is with language - I'm using C for my work and knowing this and the Q I asked you'll realise that I was heavily hung over yesterday! A standard C compiler (gcc, etc) cannot optimise a binary library (well there are one or two projects that can do this but they require you to link their libs to the ones needing optimisation) or even seperate it more efficently ie a C compilers granularity is to the library level.

    Dizz

    E&OE :p


  • Registered Users Posts: 491 ✭✭flav0rflav


    Some C compilers will pull all the library in. Most will try and just pull in the bits needed. They will not try and optimise library code, as it is assumed to already be optimised.

    Java is dynamically linked.

    You can see lots of details about exactly what has happend by looking at the linker generated map file, or list file. You may have to turn on the output of this info. But well worth a look from time to time.


  • Registered Users Posts: 648 ✭✭✭Tenshot


    Also be warned that functions in a library are often interconnected - calling sprintf() will usually pull in a ton of other support functions as well.

    Some compilers* try to be clever and, for example, if you only call printf() with simple parameters like %d and %s, will internally optimise it to __simple_printf() which needs far fewer support functions. In this way, the amount of extra stuff pulled in can be kept to a minimum, which is handy when you're writing very short programs.

    ---
    * The one I'm thinking of is the old SAS/C compiler for the Amiga, but I'm sure there are others....


  • Advertisement
  • Registered Users Posts: 21,264 ✭✭✭✭Hobbes


    Originally posted by Ruaidhri
    i dunno..it's always bugged me.
    speaking about java(specifically) i always presumed that an import statement like import java.io.* would only import the specifiy classes referenced in the code. of course i'm stil not sure,and a compiler is still a little complex for me to tackle.

    it would be intresting to know..it would help me to write more stremlined code.

    it this what you were after?

    I normally just import the actual classes I am using rather then '.*'. It is easier to keep track of what is being used.

    Eclipse will also do this for you (using Source->Organize Imports).


Advertisement