Pages: 1 2 [3]   Go Down
Author Topic: Why use int instead of byte for pin numbers?  (Read 3647 times)
0 Members and 1 Guest are viewing this topic.
Worst state in America
Offline Offline
God Member
*****
Karma: 32
Posts: 819
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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!  smiley
Logged

Gentlemen may prefer Blondes, but Real Men prefer Redheads!

Pakistan
Offline Offline
Sr. Member
****
Karma: 6
Posts: 357
Arduino rocks
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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 smiley
Logged


Birmingham, AL
Offline Offline
Jr. Member
**
Karma: 2
Posts: 91
Arduino, disobey me.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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
Logged

Global Moderator
Dallas
Online Online
Shannon Member
*****
Karma: 212
Posts: 13080
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

The latter will use more flash...

By a constant eight bytes for the entire sketch.  Hardly worth mentioning.   smiley-wink
Logged

Worst state in America
Offline Offline
God Member
*****
Karma: 32
Posts: 819
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

The latter will use more flash...

By a constant eight bytes for the entire sketch.  Hardly worth mentioning.   smiley-wink


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.
Logged

Gentlemen may prefer Blondes, but Real Men prefer Redheads!

SE USA
Offline Offline
Faraday Member
**
Karma: 41
Posts: 3783
@ssh0le
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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 smiley

you mean the wiring guys?

 smiley-evil

http://wiring.org.co/
Logged


Left Coast, CA (USA)
Offline Offline
Brattain Member
*****
Karma: 362
Posts: 17307
Measurement changes behavior
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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 smiley

you mean the wiring guys?

 smiley-evil

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
Logged

Pittsburgh, PA, USA
Offline Offline
Faraday Member
**
Karma: 99
Posts: 4836
I learn a bit every time I visit the forum.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Why do we use:
Code:
int led = 13;
instead of
Code:
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....
Logged

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

Pittsburgh, PA, USA
Offline Offline
Faraday Member
**
Karma: 99
Posts: 4836
I learn a bit every time I visit the forum.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Logged

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

Pages: 1 2 [3]   Go Up
Jump to: