Arduino Forum

Using Arduino => Programming Questions => Topic started by: stoopkid on Feb 25, 2013, 07:11 am

Title: Why use int instead of byte for pin numbers?
Post by: stoopkid on Feb 25, 2013, 07:11 am
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.
Title: Re: Why use int instead of byte for pin numbers?
Post by: Osgeld on Feb 25, 2013, 07:14 am
I always use byte for values less than 255
Title: Re: Why use int instead of byte for pin numbers?
Post by: stoopkid on Feb 25, 2013, 07:16 am
I'm thinking that's the best idea unless there is something I'm missing. Which is likely.

It's just that's the way it's done in most examples, even the arduino default ones. So I figured there may be a reason.
Title: Re: Why use int instead of byte for pin numbers?
Post by: CrossRoads on Feb 25, 2013, 07:16 am
I always use byte, not int.

sometimes even
const byte  ledPin = 13;

but generally not, because I don't allow ledPin to change value in the software.
Title: Re: Why use int instead of byte for pin numbers?
Post by: MarkT on Feb 25, 2013, 10:27 am
People often use int to avoid having to explain more datatypes - byte takes less space and
is perfectly reasonable.  const declarations allow the compiler to optimize the variable away
with luck. Also
Code: [Select]

#define led_pin 13

is fine and avoids introducing any variable.
Title: Re: Why use int instead of byte for pin numbers?
Post by: majenko on Feb 25, 2013, 12:43 pm

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.

The answer is simple:  The Arduino programmers are lazy and don't have much of a clue.  The whole of the core is riddled with wrong data types, bad practices, and generally stupid ways of doing things.  All of which end up rubbing off on users who are new to programming and blindly copy how Arduino have done things, picking up said bad habits and practices for themselves.
Title: Re: Why use int instead of byte for pin numbers?
Post by: krupski on Feb 25, 2013, 01:55 pm

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.


A "byte" type is the same as "uint8_t" (uses one byte of memory).  An "int" is an unsigned 16 bit variable (uses two bytes of memory).

For constants like "led = 13", why not just use #define led 13 ?
Title: Re: Why use int instead of byte for pin numbers?
Post by: majenko on Feb 25, 2013, 02:06 pm


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.


A "byte" type is the same as "uint8_t" (uses one byte of memory).  An "int" is an unsigned 16 bit variable (uses two bytes of memory).

For constants like "led = 13", why not just use #define led 13 ?

Because that isn't strongly typed.  Better to use:
Code: [Select]

const byte led = 13;

Then the compiler knows that it's a byte type and tells you if you do something stupid with it.
Title: Re: Why use int instead of byte for pin numbers?
Post by: krupski on Feb 25, 2013, 02:10 pm

The answer is simple:  The Arduino programmers are lazy and don't have much of a clue.  The whole of the core is riddled with wrong data types, bad practices, and generally stupid ways of doing things.  All of which end up rubbing off on users who are new to programming and blindly copy how Arduino have done things, picking up said bad habits and practices for themselves.


Well now that we are dissing Arduino, allow me to add my gripes!

The HARDWARE design is all wrong. Ever try to use the "mounting" holes on the board? Impossible. They are too close to connectors, and there are no "keep-outs" to protect traces from screw heads or standoffs.

There are not enough VCC and GND points available for prototyping.

There is no good place to clip on a ground wire (like for a scope probe).

There is not enough keep-out clearance around the ICSP connector for the MEGA16 USB processor, and BARELY enough room around the main ICSP connector.

The USB interface uses a 16.000 crystal, but the CPU uses a lousy resonator that drifts with temperature.

Don't believe this one? Setup a 60 Hz square wave (or 50 depending on where you live), watch it on your scope with the scope sync'd to the line and watch it's drift.

Then touch the resonator and you will see the frequency slowly change (drift rate changes) as it warms up.

It's not finger capacitance - the change doesn't happen immediately, it SLOWLY drifts! Remove the finger and it drifts back down.

Wonderful design where PRECISION TIMING is needed (not).

The connectors on the board should have been MALE pins, not a female header. It's much easier to make a custom female-to-female cable with Sparkfun or Pololu jumper wires and single row or dual row connectors.

Because of this, the first thing I usually do is de-solder the connectors on an Arduino and replace them with male header pins.

Voltage regulator: Why not use something more beefy like a 7805 and some decent heat sinking (or at least provide a spot to solder in an optional one)?

Pin numbers: How stupid is that? What's wrong with "PORTB, BIT 7"?

Software gripes:

Why is map() done with long ints? It's almost useless that way. I modified my library (overloaded the function) to also support floats.

Speaking of floats, why doesn't the IDE have the option to enable or disable floating point support for printf, sprintf, sscanf, etc? I had to write my own mod to add that feature!

[rant off}

Gosh I feel so much better now!  :)
Title: Re: Why use int instead of byte for pin numbers?
Post by: majenko on Feb 25, 2013, 02:18 pm


The answer is simple:  The Arduino programmers are lazy and don't have much of a clue.  The whole of the core is riddled with wrong data types, bad practices, and generally stupid ways of doing things.  All of which end up rubbing off on users who are new to programming and blindly copy how Arduino have done things, picking up said bad habits and practices for themselves.


Well now that we are dissing Arduino, allow me to add my gripes!

The HARDWARE design is all wrong. Ever try to use the "mounting" holes on the board? Impossible. They are too close to connectors, and there are no "keep-outs" to protect traces from screw heads or standoffs.

There are not enough VCC and GND points available for prototyping.

There is no good place to clip on a ground wire (like for a scope probe).

There is not enough keep-out clearance around the ICSP connector for the MEGA16 USB processor, and BARELY enough room around the main ICSP connector.

The USB interface uses a 16.000 crystal, but the CPU uses a lousy resonator that drifts with temperature.

Don't believe this one? Setup a 60 Hz square wave (or 50 depending on where you live), watch it on your scope with the scope sync'd to the line and watch it's drift.

Then touch the resonator and you will see the frequency slowly change (drift rate changes) as it warms up.

It's not finger capacitance - the change doesn't happen immediately, it SLOWLY drifts! Remove the finger and it drifts back down.

Wonderful design where PRECISION TIMING is needed (not).

The connectors on the board should have been MALE pins, not a female header. It's much easier to make a custom female-to-female cable with Sparkfun or Pololu jumper wires and single row or dual row connectors.

Because of this, the first thing I usually do is de-solder the connectors on an Arduino and replace them with male header pins.

Voltage regulator: Why not use something more beefy like a 7805 and some decent heat sinking (or at least provide a spot to solder in an optional one)?

Pin numbers: How stupid is that? What's wrong with "PORTB, BIT 7"?

Software gripes:

Why is map() done with long ints? It's almost useless that way. I modified my library (overloaded the function) to also support floats.

Speaking of floats, why doesn't the IDE have the option to enable or disable floating point support for printf, sprintf, sscanf, etc? I had to write my own mod to add that feature!

{rant off}

Gosh I feel so much better now!  :)

... and you're barely scratching the surface ...

You forgot to mention the 160 mil spacing of the digital headers - makes it almost impossible to use perfboard / stripboard for prototyping.

And why cripple it with an Atmel chip anyway?  That was a bad idea from the outset ;)

Another nice option would have been a jumper to select the chip's Vcc - set it to 3.3v if you want to use 3.3v peripherals - saves all that faffing around with level shifters or butchering you board to make it 3.3v.

And why the hell did they use a full size USB socket?  Those things are useless - On one of my UNO boards I have to hold the cable in the right position to be able to program it, and the sockets get in the way of any through-hole components on the shield above.  I have little foam pads stuck to my sockets.  Mini B sockets (like everyone else in the industry uses) would have been just a bit better ;)
Title: Re: Why use int instead of byte for pin numbers?
Post by: krupski on Feb 25, 2013, 03:23 pm


... and you're barely scratching the surface ...

You forgot to mention the 160 mil spacing of the digital headers - makes it almost impossible to use perfboard / stripboard for prototyping.

And why cripple it with an Atmel chip anyway?  That was a bad idea from the outset ;)

Another nice option would have been a jumper to select the chip's Vcc - set it to 3.3v if you want to use 3.3v peripherals - saves all that faffing around with level shifters or butchering you board to make it 3.3v.

And why the hell did they use a full size USB socket?  Those things are useless - On one of my UNO boards I have to hold the cable in the right position to be able to program it, and the sockets get in the way of any through-hole components on the shield above.  I have little foam pads stuck to my sockets.  Mini B sockets (like everyone else in the industry uses) would have been just a bit better ;)


Gee... I have to agree with everything you said. I forgot about that goofy pin spacing problem. I wonder if it was a mistake in the initial design that had to be carried through for "compatibility" or if it's intentional so that specially spaced "shields" (i.e. something they can sell) have to be used instead of plain old perfboard?
Title: Re: Why use int instead of byte for pin numbers?
Post by: majenko on Feb 25, 2013, 03:24 pm



... and you're barely scratching the surface ...

You forgot to mention the 160 mil spacing of the digital headers - makes it almost impossible to use perfboard / stripboard for prototyping.

And why cripple it with an Atmel chip anyway?  That was a bad idea from the outset ;)

Another nice option would have been a jumper to select the chip's Vcc - set it to 3.3v if you want to use 3.3v peripherals - saves all that faffing around with level shifters or butchering you board to make it 3.3v.

And why the hell did they use a full size USB socket?  Those things are useless - On one of my UNO boards I have to hold the cable in the right position to be able to program it, and the sockets get in the way of any through-hole components on the shield above.  I have little foam pads stuck to my sockets.  Mini B sockets (like everyone else in the industry uses) would have been just a bit better ;)


Gee... I have to agree with everything you said. I forgot about that goofy pin spacing problem. I wonder if it was a mistake in the initial design that had to be carried through for "compatibility" or if it's intentional so that specially spaced "shields" (i.e. something they can sell) have to be used instead of plain old perfboard?

My guess is the latter ;)  But that's the cynic in me getting out again.  Wait a minute, I *am* the cynic in me!!!!
Title: Re: Why use int instead of byte for pin numbers?
Post by: Osgeld on Feb 25, 2013, 03:53 pm

Also
Code: [Select]

#define led_pin 13

is fine and avoids introducing any variable.


yea, I am getting close to the edge of ram in one of my project, changed all my const X's to #defines and freed up almost 2 dozen bytes of ram
Title: Re: Why use int instead of byte for pin numbers?
Post by: majenko on Feb 25, 2013, 03:56 pm


Also
Code: [Select]

#define led_pin 13

is fine and avoids introducing any variable.


yea, I am getting close to the edge of ram in one of my project, changed all my const X's to #defines and freed up almost 2 dozen bytes of ram

Surprising that, since const variables are stored in progmem, not in RAM...

Once it has gone through the compiler there is no difference between
Code: [Select]

const byte X = 4;

and
Code: [Select]

#define X 4
Title: Re: Why use int instead of byte for pin numbers?
Post by: krupski on Feb 25, 2013, 04:04 pm

yea, I am getting close to the edge of ram in one of my project, changed all my const X's to #defines and freed up almost 2 dozen bytes of ram


If you are running out of ram, it may be in part due to not having constants in PROGMEM.

For example, if you do this:

Serial.print("Sensor control - Main Menu");

that string is copied into SRAM and wastes it. If you do this instead:

Serial.print(F("Sensor control - Main Menu"));

or this:

Serial.print_P(PSTR("Sensor control - Main Menu"));

the string will be copied from program memory directly to the output and not use any SRAM.

Another way to save SRAM is to use MALLOC() and FREE() to dynamically allocate and de-allocate buffers on the fly, rather than having several defined all the time. Or, use one common buffer among all functions that need it.

I'll bet though you will gain the most savings by moving all your constants into PROGMEM where possible.

Hope this helps.
Title: Re: Why use int instead of byte for pin numbers?
Post by: AWOL on Feb 25, 2013, 06:35 pm
Quote
And why cripple it with an Atmel chip anyway?  That was a bad idea from the outset

Wow! A sudden outbreak of 20:20 hindsight.

Except, the hindsight needs a little focus.

Back in 2005, which useful cheap microcontroller families were supported by free, un-hobbled compilers?
Hint: it's a very short list.
Title: Re: Why use int instead of byte for pin numbers?
Post by: retrolefty on Feb 25, 2013, 06:51 pm
I will neither praise nor criticize the many arduino design points (hardware and software, of which some seem valid to me and some silly) being brought up in this post, but rather just celebrate the vast popularity of the arduino platform and the huge membership of this forum, even consisting of some members that think they got it all wrong.  :D

If I was to add to the critic list, I would be tempted to add:

Auto-reset circuit that has had many revisions and cannot be defeated with an easy switch or jumper clip selection.

Auto-voltage selection circuit that is complex, forces the priory selection if both voltage sources are available. Should have been a simple jumper clip like an early arduino board had.

Latest rev 3 uno and mega boards that use pin 13 led opamp driver/buffer that has a floating input pin condition allowing the led to randomly be on or off if not forced low by a pin 13 output mode and digital output LOW commands.

Lefty

Title: Re: Why use int instead of byte for pin numbers?
Post by: majenko on Feb 25, 2013, 07:18 pm

I will neither praise nor criticize the many arduino design points (hardware and software, of which some seem valid to me and some silly) being brought up in this post, but rather just celebrate the vast popularity of the arduino platform and the huge membership of this forum, even consisting of some members that think they got it all wrong.  :D

It's just like Windows.  Just because everyone uses it, doesn't make it good.
Title: Re: Why use int instead of byte for pin numbers?
Post by: retrolefty on Feb 25, 2013, 07:31 pm


I will neither praise nor criticize the many arduino design points (hardware and software, of which some seem valid to me and some silly) being brought up in this post, but rather just celebrate the vast popularity of the arduino platform and the huge membership of this forum, even consisting of some members that think they got it all wrong.  :D

It's just like Windows.  Just because everyone uses it, doesn't make it good.


Yea, many seem to hate all oil companies but still buy their gasoline.  ;)

Disclaimer, retired oil company employee. Great job, great company, some great supervisors, some piss poor ones also.  :D

Lefty
Title: Re: Why use int instead of byte for pin numbers?
Post by: nickgammon on Feb 26, 2013, 12:52 am

yea, I am getting close to the edge of ram in one of my project, changed all my const X's to #defines and freed up almost 2 dozen bytes of ram


Proof? Constants don't take up RAM.
Title: Re: Why use int instead of byte for pin numbers?
Post by: nickgammon on Feb 26, 2013, 01:02 am
Quote
Well now that we are dissing Arduino, allow me to add my gripes!


Yes, very good, but the design is good enough that they are selling tens of thousands. The good points are that it is aimed at the beginner market, the shields are a useful add-on, and it was an excellent decision to use the open-source g++ compiler.

Compare that to other boards where you have to buy their own (dodgy) compilers, or get a cut-down "beginner" version, and put up with an IDE that is so complex it's almost impossible to get a project up quickly.
Title: Re: Why use int instead of byte for pin numbers?
Post by: stoopkid on Feb 26, 2013, 01:05 am

Quote
Well now that we are dissing Arduino, allow me to add my gripes!


Yes, very good, but the design is good enough that they are selling tens of thousands. The good points are that it is aimed at the beginner market, the shields are a useful add-on, and it was an excellent decision to use the open-source g++ compiler.

Compare that to other boards where you have to buy their own (dodgy) compilers, or get a cut-down "beginner" version, and put up with an IDE that is so complex it's almost impossible to get a project up quickly.


Yeah I figure, maybe they weren't the best programmers or engineers but they did create the best, most successful beginner development board and IDE so there's something to be said about that.
Title: Re: Why use int instead of byte for pin numbers?
Post by: graynomad on Feb 26, 2013, 05:17 am
@majenko and Krupski
All the above gripes have been posted many times, some even by me. I don't understand many of the design decisions made by Arduino either but the often dubious "features" haven't stopped it becoming a success.

As someone who has never had such a runaway success despite spending a lifetime trying to produce good hardware and software design I find it quite discouraging and another case of both marketing over function and being in the right place at the right time with the right product. Also the fact that most users don't give a rodent's posterior as long as they can get a LED to blink in time with the music :)

_____
Rob
Title: Re: Why use int instead of byte for pin numbers?
Post by: nickgammon on Feb 26, 2013, 05:27 am
Wait, you can get the LEDs to blink in time with music? I must try that ...
Title: Re: Why use int instead of byte for pin numbers?
Post by: AWOL on Feb 26, 2013, 07:47 am
Quote
the shields are a useful add-on
...and difficult for beginners to plug in the wrong way round  ;)
Title: Re: Why use int instead of byte for pin numbers?
Post by: nickgammon on Feb 26, 2013, 07:51 am
Exactly! And that is what was so brilliant about the original design. :)
Title: Re: Why use int instead of byte for pin numbers?
Post by: PeterH on Feb 26, 2013, 04:16 pm
I think it's fair to say that the Arduino is designed for and marketed towards people who don't know any better. Obviously there are people here who can see ways to improve the development environment, runtime library (and its documentation) and the hardware. (No matter how good it was, that would always be the case.) But these are not the people that Arduino targets.
Title: Re: Why use int instead of byte for pin numbers?
Post by: krupski on Feb 26, 2013, 04:31 pm

Yea, many seem to hate all oil companies but still buy their gasoline.  ;)


There is little choice other than to bicycle or walk (both of which are impractical in cold weather and/or long distances).
Title: Re: Why use int instead of byte for pin numbers?
Post by: majenko on Feb 26, 2013, 04:41 pm


Yea, many seem to hate all oil companies but still buy their gasoline.  ;)


There is little choice other than to bicycle or walk (both of which are impractical in cold weather and/or long distances).

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.
Title: Re: Why use int instead of byte for pin numbers?
Post by: krupski on Feb 26, 2013, 04:42 pm

Quote
Well now that we are dissing Arduino, allow me to add my gripes!


Yes, very good, but the design is good enough that they are selling tens of thousands. The good points are that it is aimed at the beginner market, the shields are a useful add-on, and it was an excellent decision to use the open-source g++ compiler.

Compare that to other boards where you have to buy their own (dodgy) compilers, or get a cut-down "beginner" version, and put up with an IDE that is so complex it's almost impossible to get a project up quickly.


I'm not saying Arduino is "bad", I just have gripes about the design. The ONLY reason I use Arduino is because of the great GCC support.

The boards, at the very least, should have usable mounting holes. People actually do build REAL projects with Arduino boards and it's ridiculous to either need special plastic standoffs or double sided foam tape to mount the board!

And, the Atmel AVR line certainly isn't the best choice for a microcontroller, but it's good enough for most uses.

I personally prefer the "Motorola" style (von Neumann) CPU architecture. The Harvard / Intel / AVR style architecture is a nightmare to work with. Thankfully, the C libraries shield me from most of that grief...
Title: Re: Why use int instead of byte for pin numbers?
Post by: krupski on Feb 26, 2013, 04:43 pm

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!  :)
Title: Re: Why use int instead of byte for pin numbers?
Post by: Khalid on Feb 26, 2013, 05:21 pm
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 :)
Title: Re: Why use int instead of byte for pin numbers?
Post by: transfinite on Feb 26, 2013, 06:14 pm
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
Title: Re: Why use int instead of byte for pin numbers?
Post by: Coding Badly on Feb 27, 2013, 04:21 am
The latter will use more flash...


By a constant eight bytes for the entire sketch.  Hardly worth mentioning.   ;)
Title: Re: Why use int instead of byte for pin numbers?
Post by: krupski on Feb 27, 2013, 04:34 pm

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.
Title: Re: Why use int instead of byte for pin numbers?
Post by: Osgeld on Feb 28, 2013, 06:45 am

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/
Title: Re: Why use int instead of byte for pin numbers?
Post by: retrolefty on Feb 28, 2013, 02:07 pm


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
Title: Re: Why use int instead of byte for pin numbers?
Post by: GoForSmoke on Feb 28, 2013, 02:09 pm

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....
Title: Re: Why use int instead of byte for pin numbers?
Post by: GoForSmoke on Feb 28, 2013, 02:15 pm

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

Title: Re: Why use int instead of byte for pin numbers?
Post by: callmebob on Mar 05, 2018, 04:39 pm
A "byte" type is the same as "uint8_t" (uses one byte of memory).  An "int" is an unsigned 16 bit variable (uses two bytes of memory).
 
Thanks krupski, for this informative answer. After going back to it now, I see this info is in the reference data, but I didn't absorb it like I did in your statement.
Title: Re: Why use int instead of byte for pin numbers?
Post by: UKHeliBob on Mar 05, 2018, 04:42 pm
Thanks krupski, for this informative answer.
WOW

5 years later
Title: Re: Why use int instead of byte for pin numbers?
Post by: callmebob on Mar 05, 2018, 04:57 pm
Oops, reviving a dead thread... sorry was so thrilled with the answer, I didn't read any dates.

After UKHeliBob's informative reply I noticed the dates. Thanks to the wonderful feature of this board, I had to wait 5 minutes before editing or deleting it.

Just a thought... it might be 5 years to you all, but it was only 15 minutes old to me :)
Title: Re: Why use int instead of byte for pin numbers?
Post by: UKHeliBob on Mar 05, 2018, 05:43 pm
Quote
Thanks to the wonderful feature of this board, I had to wait 5 minutes before editing or deleting it.
You are halfway to having the 5 minutes between posts restriction lifted (100 posts needed I believe)
Title: Re: Why use int instead of byte for pin numbers?
Post by: Cosme_Fulanito on Mar 05, 2018, 05:55 pm
Arduino is not alone on this. There is an ongoing trend among computer programmers, and that is that you don't think that much about anything. One of those things you don't think about is data types. AT ALL.

Remember that "incident" (oh the horror!) on Youtube where the play count for Gangman Style rolled over?

They were using signed integers to store that. It would have taken a semi competent programmer of any seniority, let alone architect, to realize that it takes the same space and processing power to just use an unsigned integer, but that's not "standard", that's not "modern", modern is to use whatever holds numbers.

The base integer type of the language/platform gets used for anything numeric that doesn't need decimal places. Period.

Title: Re: Why use int instead of byte for pin numbers?
Post by: UKHeliBob on Mar 05, 2018, 06:03 pm
Quote
One of those things you don't think about is data types. AT ALL.
There are programming languages that don't actually have data types.  Whilst this provides great freedom it does teach you to be very careful.  Debugging can be fun.
Title: Re: Why use int instead of byte for pin numbers?
Post by: GrooveFlotilla on Mar 05, 2018, 06:20 pm
Quote
They were using signed integers to store that. It would have taken a semi competent programmer of any seniority, let alone architect, to realize that it takes the same space and processing power to just use an unsigned integer,
Java mentality.
Title: Re: Why use int instead of byte for pin numbers?
Post by: INTP on Mar 05, 2018, 09:04 pm
When's the last time you ever saw a perfect product that pleased everybody?
Title: Re: Why use int instead of byte for pin numbers?
Post by: MarkT on Mar 05, 2018, 10:53 pm
yea, I am getting close to the edge of ram in one of my project, changed all my const X's to #defines and freed up almost 2 dozen bytes of ram

Surprising that, since const variables are stored in progmem, not in RAM...

Once it has gone through the compiler there is no difference between
Code: [Select]

const byte X = 4;

and
Code: [Select]

#define X 4

Nope, they are different, as has been proven by experiment with the actual compiler and
the actual compiler optimization settings used in the environment.  There is definitely no
requirement to store const variables in read only memory, its just a possible optimization.