Pages: 1 [2]   Go Down
Author Topic: Curious about pin declare...  (Read 859 times)
0 Members and 1 Guest are viewing this topic.
Global Moderator
Dallas
Offline Offline
Shannon Member
*****
Karma: 208
Posts: 12936
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Actually, my entire argument is based upon the ANSI standard definition.

Which defines a hypothetical compiler.  I'm glad we agree.

Quote
Given this is the forum to discuss other microcontrollers and not just the microcosm of Arduino, I think I'll stick with standard C and not what some particular compiler may or may not do with optimizations.

So @kokpat posts his question in the wrong section and you feel compelled to start a discussion of standard C++?  If that's really how you want to spend your time you are certainly welcome to have at it.  I have better things to do...
Logged

texas
Offline Offline
God Member
*****
Karma: 27
Posts: 862
old, but not dead
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Actually, my entire argument is based upon the ANSI standard definition.

Which defines a hypothetical compiler.  I'm glad we agree.

Quote
Given this is the forum to discuss other microcontrollers and not just the microcosm of Arduino, I think I'll stick with standard C and not what some particular compiler may or may not do with optimizations.

So @kokpat posts his question in the wrong section and you feel compelled to start a discussion of standard C++?  If that's really how you want to spend your time you are certainly welcome to have at it.  I have better things to do...


Look, I didn't hijack this thread.  I was only trying to add to the discussion by asking a simple question about #define vs const.  You called me out specifically and I tried to answer your questions, condescending as they were.  And now, because you didn't like my answers, instead of presenting a technical argument you chose to be rude about it and accuse me of being a thread jacker.  Why???  I haven't done anything with any intention of insulting you.  I only disagreed with you on some things technically.  If you have a technical argument, bring it on I'm all in for it.  No need to be insulting.

Of course the OP's question is legitimate, no need to put words into my mouth either.
« Last Edit: May 05, 2013, 01:09:21 am by afremont » Logged

Experience, it's what you get when you were expecting something else.

Global Moderator
Dallas
Offline Offline
Shannon Member
*****
Karma: 208
Posts: 12936
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
...by asking a simple question...
Quote
Why waste the storage space?

A question that implies the GCC compiler does not optimize const declarations.  That is not a "simple question".

Quote
...I tried to answer your questions...

Your responses are based on a hypothetical compiler.  Perfect answers on a C++ standards forum.  Or, in a response to a question about portability.  The compiler in question is not hypothetical, this is not a standards forum, and the question was not about portability.

Quote
I haven't done anything with any intention of insulting you.

I do not feel insulted.  Thank you for your concern.

Quote
No need to be insulting.

Even though I fail to understand why you feel insulted it makes no difference.  I apologize for insulting you.

Quote
If you have a technical argument...

I have already stated my position.  I will not engage in any argument about a hypothetical compiler.  You are free to do as you please.

Quote
...bring it on I'm all in for it

"Bring it on"?  No thanks.
Logged

United Kingdom
Offline Offline
Tesla Member
***
Karma: 224
Posts: 6619
Hofstadter's Law: It always takes longer than you expect, even when you take into account Hofstadter's Law.
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Actually, my entire argument is based upon the ANSI standard definition. Given this is the forum to discuss other microcontrollers and not just the microcosm of Arduino, I think I'll stick with standard C and not what some particular compiler may or may not do with optimizations.

If you want to stick with standard C, don't use the Arduino IDE. The IDE uses a C++ compiler, not C, and C++ has different semantics from C. One of the many differences between C and C++ is how file-level declarations such as "const int pin = 5;" are treated.
Logged

Formal verification of safety-critical software, software development, and electronic design and prototyping. See http://www.eschertech.com. Please do not ask for unpaid help via PM, use the forum.

texas
Offline Offline
God Member
*****
Karma: 27
Posts: 862
old, but not dead
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Ok then on the apology, thank you.  smiley  <--- I still think that thing looks silly, but whatever.  Anyhow, ANSI C isn't something hypothetical, it's what all workable compilers are based upon.  If GCC optimizes const away then that's cool, but I'm sure it would afford the same luxury to the repetitive occurrences of constant type values that were stuffed in by the preprocessor thru the use of #define.  I can see the benefit of securing the type, especially in the minds of native C++ coders that tend to worry about such things.  But I also appreciate the efficiency of letting the compiler pick the type on an as needed basis.  

This brings us to the OP's original question.  I think the answer is more a matter of monkey see monkey do with the int LEDPin thing.  It's certainly not the most efficient way and it's even the wrong basic type to supply as arguments to the functions. But, it is what you will see throughout the examples.

I thought it was simple enough, I just wanted to know why the local allegiance to const over #define.  It seemed to be perfectly appropriate to the course of the conversation at that point.  At least I thought so.

The "bring it on" thing is about debate, not a duel.  I like to argue about technical matters, it's how I learn.  I am also willing to admit I'm wrong when there is a technical backing to the counter-claim.  I'm not a big fan of "because I said so", or "that's the way it is here" etc.  I like to see real proof and hear real logical reasoning behind an argument.  When I post, I expect to be questioned if I make a technical error.  I don't expect to be admonished for something I didn't do.

I apologize to the OP for this diversion.  I like to try and help, but sometimes I guess I rub some folks the wrong way.  
Logged

Experience, it's what you get when you were expecting something else.

texas
Offline Offline
God Member
*****
Karma: 27
Posts: 862
old, but not dead
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Actually, my entire argument is based upon the ANSI standard definition. Given this is the forum to discuss other microcontrollers and not just the microcosm of Arduino, I think I'll stick with standard C and not what some particular compiler may or may not do with optimizations.

If you want to stick with standard C, don't use the Arduino IDE. The IDE uses a C++ compiler, not C, and C++ has different semantics from C. One of the many differences between C and C++ is how file-level declarations such as "const int pin = 5;" are treated.

Ok, so it's really a fine distinction between C and C++ definitions of const.  I see that they are a little differently treated by the C++ compiler as "true constants" whereas in C, they aren't so-called true constants.  The only similar "true constants" in C are enums.  So in a C world, the correct answer is use a #define, but in a C++ world const gives some benefit without using storage.  Ok, I can cope with that.  Thanks for getting me pointed in the right direction.   

Logged

Experience, it's what you get when you were expecting something else.

Pages: 1 [2]   Go Up
Jump to: