This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

HPs

Let me tell you a story about a guy named Jed...

A long long time ago (pre-ANSI C), in a galaxy far far away I had worked for a company that had to develop internal "C" coding standards and "Jed" worked on one aspect of the standard while I worked on another. We would hold weekly meetings to reconcile our differences. In attendance, we had other professionals for simple sanity checking and to gain insights from different points of view.

Chris was one of our attendees and was a very experienced software veteran who had plenty of code in various satellite systems orbiting our planet today. By then, Chris was in upper management and graced us with his wisdom when he could.

Well during one of our weekly meetings, "Jed" and I got into a simple disagreement on a Rule about header files. We were at an impasse, so we waited for Chris to arrive and have him make the final decision: about five of us professional engineers were in the room.

When Chris arrived, he heard the arguments, and quickly announced that I was right. (Hence, Jed was wrong).

Well, Jed freaked out and wanted to take the guy outside and teach him a lesson! ... Jed was red-faced, quickly stood up, even took a step towards Chris, and said "Chris, lets just step outside and settle this! I am right and you don't know what you're talking about!" etc etc.

The other attendees and I were duly impressed over Jed's technique of handling technical disagreements. Especially with upper management.

Instead of Jed trying to learn that he *might* be wrong, Jed leaped into the confrontation method of getting his way. Bullies do this because they lack the brain-power to reason through a disagreement. It is a childish trait.

Children are at a huge disadvantage when arguing with "an adult" (or somebody who is much smarter than they are) and they will become very frustrated over their strong desire to assert themselves and their inability to win the mental sparring. They will get physical and/or verbally abusive. Some people out grow this, and some don't.

I think Jed showed his 'abilities' quite well. I find that this is true with so many people on so many subjects. I've seen this behavior many times over. I've seen it here on this forum.

When an "Original Poster", asks a question and people try to answer it (after much refinement of the OP's question) you get these side-bar posts where somebody will start attacking another poster's efforts. And I mean 'attack' and not augment or refine.

I don't have a problem with correcting or clarifying others, or even the occasional sprinkling of sarcasm, but when it is ALWAYS devolves into some vindictive vitriol between a brisling poster and the rest of 'us,' I wonder if it is out of ignorance, malice, or some twisted form of self-entertainment. All three of which are adolescent behaviors. (en.wikipedia.org/.../Adolescence)

Since the regular players here are detail oriented and thus they are savvy enough to know who I'm talking about, I don't think I have to name names.

He is critical enough to figure it out himself, so I would expect that the offender would read this and ask himself if he is demonstrating Ignorance, Malice, Entertainment, or is he being an adult and providing a constructive post before he does so.

And, I hope his "Mea Clupea" (en.wikipedia.org/.../Mea_culpa) will be a silent one, because I'm kind of tired of reading his Hostile Postings (HP).

</rant>
--Cpt. Vince Foster
2nd Cannon Place
Fort Marcy Park, VA

  • Jack, Erik,

    I don't know how Keil handle bit fields for the C51, but for an ARM it is certainly a bad idea to use them, due to the following reasons:

    * Jack must agree with me that bit fields are not really a solid part of the C standard. compilers seem to have artistic freedom when dealing with them which can yield more or less efficient code (packing of structures...).
    * because all ARM registers are 32 bit, 2 instructions are required to test a bit: a shift to right, then a separate instruction to test the value.

    it is much faster to use a 32 bit integer as a container for your bit fields.

    I wonder: what is more efficient for a C51? using a bit field or an 8 bit integer?

  • Tamir,

    A bit in C51 is there to specifically use the bit storage area of the CPU. There is a block of 128 bits that are a little like prime real estate. They are particularly useful for boolean operations.

    C51 has access to this area with a specific extension.

    When considering porting, they are not such a big issue - And I see the usual stubborness being exhibited by a certain poster.

    Generally, I would not consider using the bit directly within the code, but would instead use a typedef such as:

    #if C51
      typedef bit Flag;
    #else
      typedef unsigned char Flag;
    #endif
    

    This is put into a header file with all other port related details.

    So whats so difficult about it? Nothing!

  • you conveniently ignore that while "keil C" has a variable named BIT, you will not find that in the "ISO (formerly ANSI) Standard 'C'"

    How do you reconcile the fact that C51 is an ANSI/ISO 'C' compiler with the existence of 'bit', I wonder?

    well, I asked, why do you not answer instead of 'wonder"

    You didn't ask anything, you made a statement to which I responded with a question. In any case, given that you treat any suggestion that you have not read the standard as a "baseless accusation" then I'm sure you'll feel insulted if I suggest that you might not know the answer to my question.

    Do you still claim to have read the ISO 'C' standard?

    how can this be portable without preprocessor directives
    #if COMPILER == C51 ....

    It isn't portable. Wrapping code in preprocessor directives doesn't make it portable - in fact, it makes it clear that it is non-portable.

    NOTE: it is, of course, possible to just use the OR and ignore the efficiency, but what if the C51 project is time critical

    I'd be unlikely to have designed my way into a situation where a bit operation rather than a byte operation would make the difference between project success and project failure. Perhaps you write the code, compile and count the clock cycles before you select the processor and oscillator?

    and the ACME project is not because it runs on a much faster processor

    Ah, glad to see you agree with me. Use a faster processor.

    If the above is not "to your liking" come out of your hole and state what I suspect is your position that you do not give a hoot about efficiency.

    I care about efficiency where efficiency is the most important factor. With sensible design, however, it rarely is.

    In short "Wrapping code in preprocessor directives doesn't make it portable - in fact, it makes it clear that it is non-portable" is contradicted by your own statements.

    Really? Which ones?

  • #if C51
      typedef bit Flag;
    #else
      typedef unsigned char Flag;
    #endif
    

    Rob, according to whoever hides behind "Jack Sprat", you are wrong, I quote:
    "Wrapping code in preprocessor directives doesn't make it portable - in fact, it makes it clear that it is non-portable."

    evidently you are supposed to make your code portable without using "preprocessor directives"

    Erik

  • Ah, glad to see you agree with me. Use a faster processor.

    Alas, in the real world, that is not always an option. Processors for embedded systems rarely get chosen for their ability to run 'portable' (and hence larger, slower) code - they get chosen for their ability to 'barely run the application for the lowest cost' - in this case - optimising for every last clock cycle can become an issue, especially when feature creep sets in.

  • evidently you are supposed to make your code portable without using "preprocessor directives"

    Well taken to extremes, that is sheer nonsense; but I do not think (or hope) this is what is being said.

    I have plenty of code that runs on different cores where the only difference is a single 'processor/core specific' header file.

    At the very least, typedefs that provide specific width variables (e.g., 8, 16, 32) is nothing short of essential.

  • a) "I care about efficiency"

    In short "Wrapping code in preprocessor directives doesn't make it portable - in fact, it makes it clear that it is non-portable" is contradicted by your own statements.

    Really? Which ones? a) above for example.

    If the above is not "to your liking" come out of your hole and state what I suspect is your position that you do not give a hoot about efficiency.

    I care about efficiency where efficiency is the most important factor. With sensible design, however, it rarely is.
    translated "if cost is an issue, do not involve the person hiding behind "Jack Sprat", he cares more about his fanciful ideas"

    Erik

  • I'd be unlikely to have designed my way into a situation where a bit operation rather than a byte operation would make the difference between project success and project failure.
    so would I. Confound it, can you not understand what an example is, www.merriam-webster.com/.../example see 3)

    Erik

  • On this whole portability thing, I'm glad erik provided the glossary of terms, because when erik points out that portable code is rare, he is right in his definition of terms. I don't think ANY embedded professional would expect to write in pure "C". It would be simply smashing if they do.

    All processor variants and their cohorts in the IDE business will have special options for squeezing every last performance drop out of the final executable code.

    Be it speed or space, the need to optimize your code is driven by us, the customer. Imagine a pure "C" compiler (no deviations from the standard at all) for the 8051. To eek core performance out of it, we would complain about the gyrations we would need to go through to achieve 'assembly level' performance, and if they (Keil) would only provided a "C" variant extension called 'bit' or 'xdata' or 'data' like their competitor does, we'd be happy. We would be able to eek that performance out and be happy.

    So they do. And so does their competition, etc. But as Per points out, at least these deviations are only a stones throw away from the main road/path that The Standard has carved out. And of course going from one processor to the next are still only a stones throw way from each other on the "C" level. Without knowledge of The Standard, how can any embedded professional determine if that stone was thrown, or shot out of a Howitzer?

    I prefer to know my tools well, but at the same time, I don't want to NEED to know the tool in order to complete a task or project. If that Howitzer deviation must be taken, then I get a bit aggravated. Especially when I want my code to last years, and not be boxed into a corner due to a highly specific compiler path that cannot be logically reworked for a new or different compiler or even a new or different processor.

    I consider it portable if there is 'minimal' impact on the code and 'minimal' impact on the coder to go from one platform to another. Centralizing the non-portables or high-risk code helps, and trying to write the code closer to the 'pure' C environment aids in making code portable.

    So when we speak of 'portable' or 'nominal' or 'minimal' they are all subjective concepts, and we can go on-and-on-and-on refining what 'portable' means (and the derivative discussion on how to write it), but I doubt if there is going to be a clear-cut answer. To presume to hold The Answer is clearly spratter-brained.

    --Cpt. Vince Foster
    2nd Cannon Place
    Fort Marcy Park, VA

  • So when we speak of 'portable' or 'nominal' or 'minimal' they are all subjective concepts, and we can go on-and-on-and-on refining what 'portable' means (and the derivative discussion on how to write it), but I doubt if there is going to be a clear-cut answer. To presume to hold The Answer is clearly spratter-brained.
    "ALL code is portable, the only difference is the amount of work involved in porting it"

    so, Vince, we agree.

    Erik

  • * Jack must agree with me that bit fields are not really a solid part of the C standard.

    If Jack did agree with that, I'd have to disagree with Jack. Until then I'll just disagree with you.

    Bit fields are quite a solid part of the C standard. Their only weak aspect lies in many people's idea of what they should be used for. Suffice it to say that, like pretty much all of C's data structures, they're intended for internal data of a C program, but not for its external interfaces.

    compilers seem to have artistic freedom when dealing with them which can yield more or less efficient code (packing of structures...).

    You have that backwards. Compilers have been granted all that freedom intentionally, to allow them to generate more efficient code. If you find inefficiency, blame it on the platform or the compiler.

  • erik,

    Yep. We agree.

    "ALL code is portable, the only difference is the amount of work involved in porting it"

    I guess I could have said it that way. (Its my fingers... they ramble on sometimes---at least that is what my attorney told me to say during the trial).

    --Cpt. Vince Foster
    2nd Cannon Place
    Fort Marcy Park, VA

  • Vince,
    What trial are referring to? You may not believe me, but my team leader ordered me to change the following function name "MachineNotSafeForActiveSpreading" into something else (I chose "MachineNotReadyForActiveSpreading") out of fear of future litigation! (you see, just reminding "safety" in source code is a risk in term of future law suits if something goes wrong, when selling something in the US market!).
    Was your trial related to your software career ?

  • * Jack must agree with me that bit fields are not really a solid part of the C standard.

    If Jack did agree with that, I'd have to disagree with Jack. Until then I'll just disagree with you.
    verbiage, I think
    yes, bit fields are described fully in the standard, I guess whoever wrote "not really a solid part" really should have written "this is a section where almost every other word is 'implementation defined'"

    The "no easy seamless portability" issues comes to a large extent from the 'implementation defined' sections of the standard. That C would have been miserable to process on some processors had these thing not been 'implementation defined' is another story.

    I, for one, "have a lot of fun" processing some data which is a bunch of structures written by a processor where the byte order is "the other way around".

    Erik

  • I, for one, "have a lot of fun" processing some data which is a bunch of structures written by a processor where the byte order is "the other way around".

    Well, like I just said, writing them to files is exactly what C structs are not for. Don't blame programmer's silly decisions on their tools.