Go Down

Topic: Why use int instead of byte for pin numbers? (Read 3 times) previous topic - next topic

Krupski


There's always running...  Gets you warm in cold weather, and gets you further distance in a shorter time.
It also gives you heart attacks and knackered knees.


Most of the traces in my left knee are burned open from playing hockey. Running isn't an option for me anymore!  :)
Gentlemen may prefer Blondes, but Real Men prefer Redheads!

Khalid

I can not listen bad about Arduino... I am very thankful to the guys who gave us Free IDE and lot of libraries... And all those are very very simple to use... I love you guys :)
Simply...You can't afford me..

Author Of:
http://my-woodcarving.blogspot.com/
http://www.free3dscans.blogspot.com/
http://my-diysolarwind.blogspot.com/

Oops..some one gave me Karma...:)

transfinite

The real answer to the original question:

   Why use int instead of byte for pin numbers?

1. The programmer's time is much more expensive than the computer or compiler's time.

2. 95% of the time you are not going to need the extra few bytes saved.

3. The C++ optimizer is so good that it will rarely make any difference in code size anyway.

Two practices that will save some resources were already mentioned by majenko and Krupski in the first page of this thread:

const int instead of int for constants will some a couple bytes,
and Serial.print(F("string const")); instead of Serial.print("string const");

The latter will use more flash, but save RAM.  Conservation of RAM is usually a bigger concern than conversation of flash, in my experience.  If your code starts acting flaky you are probably running out of RAM, not flash.

-transfinite

Coding Badly

The latter will use more flash...


By a constant eight bytes for the entire sketch.  Hardly worth mentioning.   ;)

Krupski


The latter will use more flash...


By a constant eight bytes for the entire sketch.  Hardly worth mentioning.   ;)



Ah but don't you know? Everyone's sketch compiles to 32767 bytes and not a single one more will fit! (the reason for crippling sprintf and sscanf for floating point).

/saracsm off.
Gentlemen may prefer Blondes, but Real Men prefer Redheads!

Osgeld


I can not listen bad about Arduino... I am very thankful to the guys who gave us Free IDE and lot of libraries... And all those are very very simple to use... I love you guys :)


you mean the wiring guys?

]:)

http://wiring.org.co/
http://arduino.cc/forum/index.php?action=unread;boards=2,3,4,5,67,6,7,8,9,10,11,66,12,13,15,14,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,86,87,89,1;ALL

retrolefty



I can not listen bad about Arduino... I am very thankful to the guys who gave us Free IDE and lot of libraries... And all those are very very simple to use... I love you guys :)


you mean the wiring guys?

]:)

http://wiring.org.co/


Sure, along with the AVRDUDE guys, the gcc guys, the processing guys, and the java guys (I'm probably leaving others out?). The arduino platform design stands on the shoulders of many open source projects, it wasn't designed in a vacuum or a ground up effort, more like assembled from many other's open source contributions.

I think arduino's main unique contribution was their decision to open source their hardware design also which really spurred on a strong 3rd party 'compatible' and shield market that few other hardware/software micro-controller enjoy.

Lefty

GoForSmoke


Why do we use:
Code: [Select]
int led = 13;
instead of
Code: [Select]
byte led = 13;

If you would never need to define more than 256 pins, why use the extra space for int? Is there a reason?

Thanks.


That's what I do. 2k ram really isn't much, and then you try an ATtiny....
I find it harder to express logic in English than in Code.
Sometimes an example says more than many times as many words.

GoForSmoke


An "int" is an unsigned 16 bit variable (uses two bytes of memory).


Type int has always been signed in every version of C or C++ I ever used, including Arduino.
http://arduino.cc/en/Reference/Int

I find it harder to express logic in English than in Code.
Sometimes an example says more than many times as many words.

Go Up