user4672: When I've come back to Arduino programming after a spell doing other things, I keep forgetting that I last experimented with a different type of board and get a "avrdude: stk500_getsync(): not in sync: resp=0x00" error. 
I have one sketch which will always be compiled and uploaded against a specific piece of hardware. Therefore, I would like to specify the board type and preferably COM port as well, in my sketch. 
Can it be done?

user368: No, it cannot. Neither the compiler invocation nor the subsequent upload examine the code for the hardware in use, so there is no way of doing what you are asking.
What you can do is to create entries in a new boards.txt and programmers.txt using an existing core that specify all the parameters, and all you would have to do is select them in the IDE for everything to be set at once. See Google Code/Arduino/Platforms for more information.

4672: <p>When I've come back to Arduino programming after a spell doing other things, I keep forgetting that I last experimented with a different type of board and get a "avrdude: stk500_getsync(): not in sync: resp=0x00" error. </p>

<p>I have one sketch which will always be compiled and uploaded against a specific piece of hardware. Therefore, I would like to specify the board type and preferably COM port as well, in my sketch. </p>

<p>Can it be done?</p>
 368: <p>No, it cannot. Neither the compiler invocation nor the subsequent upload examine the code for the hardware in use, so there is no way of doing what you are asking.</p>

<p>What you can do is to create entries in a new <code>boards.txt</code> and <code>programmers.txt</code> using an existing core that specify all the parameters, and all you would have to do is select them in the IDE for everything to be set at once. See <a href="https://code.google.com/p/arduino/wiki/Platforms" rel="nofollow">Google Code/Arduino/Platforms</a> for more information.</p>
