Left Coast, CA (USA)
Offline
Brattain Member
Karma: 282
Posts: 15443
Measurement changes behavior
|
 |
« Reply #15 on: February 03, 2013, 12:52:16 am » |
Personally I use byte, because pin numbers are indeed unsigned, and don't go over 255.
But does for example analogRead(pin#) function cast it as a int size value inside the function? And as you said a pin number declared as a const anyway doesn't occupy any memory space on it's own, only by the thing that reference it? Lefty
|
|
|
|
« Last Edit: February 03, 2013, 12:54:07 am by retrolefty »
|
Logged
|
|
|
|
|
Des Moines, WA - USA
Offline
God Member
Karma: 25
Posts: 747
|
 |
« Reply #16 on: February 03, 2013, 12:54:39 am » |
Actually pin numbers, as used with 'digitalWrite(12, HIGH)', are in fact specified as being of type 'uint8_t' so the compiler will down convert the 'int' to an 'uint8_t' for you.
But technically you should be specifying pins as 'const uint8_t pinANALOG = A0' as an example.
|
|
|
|
« Last Edit: February 03, 2013, 12:57:07 am by lloyddean »
|
Logged
|
|
|
|
|
Left Coast, CA (USA)
Offline
Brattain Member
Karma: 282
Posts: 15443
Measurement changes behavior
|
 |
« Reply #17 on: February 03, 2013, 01:00:55 am » |
Actually pin numbers, as used with 'digitalWrite(12, HIGH)', are in fact specified as being of type 'uint8_t' so the compiler will down convert the 'int' to an 'uint8_t' for you.
But technically you should be specifying pins as 'const uint8_t pinANALOG = A0' as an example.
Ah got it, thank you. Lefty
|
|
|
|
|
Logged
|
|
|
|
|
Global Moderator
Melbourne, Australia
Offline
Shannon Member
Karma: 226
Posts: 14106
Lua rocks!
|
 |
« Reply #18 on: February 03, 2013, 01:06:06 am » |
But technically you should be specifying pins as 'const uint8_t pinANALOG = A0' as an example.
In other words, "const byte".
|
|
|
|
|
Logged
|
|
|
|
|
Left Coast, CA (USA)
Offline
Brattain Member
Karma: 282
Posts: 15443
Measurement changes behavior
|
 |
« Reply #19 on: February 03, 2013, 01:11:37 am » |
But technically you should be specifying pins as 'const uint8_t pinANALOG = A0' as an example.
In other words, "const byte". But of course now I've learned that doesn't save any real space over using const int as applied to pin number use.  Lefty
|
|
|
|
|
Logged
|
|
|
|
|
Des Moines, WA - USA
Offline
God Member
Karma: 25
Posts: 747
|
 |
« Reply #20 on: February 03, 2013, 01:17:09 am » |
My problem with 'byte' is it doesn't tell me enough about it.
I believe it is a synonym for 'unsigned char' (because its different on different platforms), but I'm never certain and alway find myself doing the double-check.
I much prefer 'uint8_t' as it's easier to know what you're getting and is the same everywhere I want to be.
|
|
|
|
|
Logged
|
|
|
|
|
Global Moderator
Melbourne, Australia
Offline
Shannon Member
Karma: 226
Posts: 14106
Lua rocks!
|
 |
« Reply #21 on: February 03, 2013, 01:35:02 am » |
That's fine, but the core type is "unsigned char" as shown here in stdint.h: /** \ingroup avr_stdint 8-bit unsigned type. */
typedef unsigned char uint8_t; You just have to remember that "unsigned char" is an 8-bit unsigned type. Using uint8_t is one typedef away from the core type. This is obviously a style issue, but for me, I prefer to remember that. It's like saying: "I want to call a dog a MammalWith2LegsThatBarks because that tells me more about it." OK, but it's really a dog. I don't want to start a "style war" here, hey next we'll be arguing about GOTO. 
|
|
|
|
|
Logged
|
|
|
|
|
Global Moderator
Melbourne, Australia
Offline
Shannon Member
Karma: 226
Posts: 14106
Lua rocks!
|
 |
« Reply #22 on: February 03, 2013, 01:36:14 am » |
I much prefer 'uint8_t' as it's easier to know what you're getting and is the same everywhere I want to be.
If they have the typedef I quoted. If not, it's an unsigned char. Hey, wait, I just shot myself in the foot here. I should be using "unsigned char" and not "byte". Oh well.
|
|
|
|
|
Logged
|
|
|
|
|
Left Coast, CA (USA)
Offline
Brattain Member
Karma: 282
Posts: 15443
Measurement changes behavior
|
 |
« Reply #23 on: February 03, 2013, 01:40:07 am » |
That's fine, but the core type is "unsigned char" as shown here in stdint.h: /** \ingroup avr_stdint 8-bit unsigned type. */
typedef unsigned char uint8_t; You just have to remember that "unsigned char" is an 8-bit unsigned type. Using uint8_t is one typedef away from the core type. This is obviously a style issue, but for me, I prefer to remember that. It's like saying: "I want to call a dog a MammalWith2LegsThatBarks because that tells me more about it." OK, but it's really a dog. I don't want to start a "style war" here, hey next we'll be arguing about GOTO.  You own a two legged dog that barks? Post a video or it isn't true.  Lefty
|
|
|
|
|
Logged
|
|
|
|
|
Global Moderator
Melbourne, Australia
Offline
Shannon Member
Karma: 226
Posts: 14106
Lua rocks!
|
 |
« Reply #24 on: February 03, 2013, 01:46:28 am » |
I was very emotional when I wrote that. 
|
|
|
|
|
Logged
|
|
|
|
|
Des Moines, WA - USA
Offline
God Member
Karma: 25
Posts: 747
|
 |
« Reply #25 on: February 03, 2013, 02:19:51 am » |
Nick - I'm not sure what your getting at or if you're upset or not.
Just saying for me it's ambiguous as to if it's signed or unsigned (unless I look it up) where as 'uint8_t' it's clear that it's unsigned and is unsigned on all platforms where as 'byte' if expressed at all can be either.
|
|
|
|
|
Logged
|
|
|
|
|
Global Moderator
Melbourne, Australia
Offline
Shannon Member
Karma: 226
Posts: 14106
Lua rocks!
|
 |
« Reply #26 on: February 03, 2013, 02:25:14 am » |
I'm only upset that I thought a dog had two legs.
|
|
|
|
|
Logged
|
|
|
|
|
Left Coast, CA (USA)
Offline
Brattain Member
Karma: 282
Posts: 15443
Measurement changes behavior
|
 |
« Reply #27 on: February 03, 2013, 02:28:11 am » |
I'm only upset that I thought a dog had two legs.
Well they do have two legs, plus two more. 
|
|
|
|
|
Logged
|
|
|
|
|
Temple, Texas
Offline
Sr. Member
Karma: 14
Posts: 354
|
 |
« Reply #28 on: February 03, 2013, 02:39:24 am » |
I think many people who know better, sometimes just use int instead, when trying to help someone to whom uint8_t or--even byte--would cause additional confusion. One can't learn everything at once...
|
|
|
|
|
Logged
|
|
|
|
|
Global Moderator
Melbourne, Australia
Offline
Shannon Member
Karma: 226
Posts: 14106
Lua rocks!
|
 |
« Reply #29 on: February 03, 2013, 02:46:29 am » |
Well they do have two legs, plus two more.  Two legs, squared?
|
|
|
|
|
Logged
|
|
|
|
|
|