1. Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.
    Dismiss Notice

C Programming: pointers

Discussion in '8051/8951' started by CroneA, Nov 5, 2013.

  1. nsaspook

    nsaspook Well-Known Member

    Joined:
    Mar 24, 2010
    Messages:
    1,141
    Likes:
    219
    Location:
    Fairview, Or
    I would say no to that. Some of the best HLL systems produce some of the most human unreadable and unstructured code possible when full optimization is enabled. All of the horrible tricks we don't want humans to use for optimization are used by the (gcc) RTL code generator backend because it's mainly solving an equivalence problem not a direct programming problem.
     
  2. 3v0

    3v0 Coop Build Coordinator Forum Supporter

    Joined:
    Jul 14, 2006
    Messages:
    9,404
    Likes:
    227
    Location:
    OKLAHOMA USA
    I was thinking of the straight translation with all optimizations off.
     
  3. nsaspook

    nsaspook Well-Known Member

    Joined:
    Mar 24, 2010
    Messages:
    1,141
    Likes:
    219
    Location:
    Fairview, Or
    But who actually uses that mode on finished code if they have a choice? I and most others use it (optimizations off) to speed up the incremental coding and debug stages where straight translation of machine code output is usually faster compiling and easier for a debugger to track source symbols to viewed machine code. Highly structured code is usually not the most efficient (fastest and/or smallest) way to translate a programming function to run-able code on a computer. I understand why many people love ASM programming, the symbolic structure that can enhance human creativity and problem solving in a HLL like C can be stripped down to a precise placement of operations instead. That works great and is efficient as long as there is a rough equivalence of the current problem to machine code but as problems become more abstract the ability to find an direct equivalence at the machine level requires a translation step by a human or computer. The level of efficiency of the sometimes incomprehensible computer translation is what makes C popular in embedded programming.
     
  4. dave

    Dave New Member

    Joined:
    Jan 12, 1997
    Messages:
    -
    Likes:
    0


     
  5. Ian Rogers

    Ian Rogers Super Moderator Most Helpful Member

    Joined:
    Mar 28, 2011
    Messages:
    9,170
    Likes:
    910
    Location:
    Rochdale UK

    Do you not find that writing a decent sized program, even for testing purposes, is tons quicker in C... I can write a program incredibly quickly in C... I know the same can be done in assembly, but the speed of writing plus the speed of debugging is oodles better than pure assembly... This for hours worked is far more efficient..

    The other thing is... If I have written a peice of code to make a pic16f887 read a pin and display the results on a LCD screen.... If I discover part way through that the pic16 is too small and I need a pic18 or pic24... All my coding isn't in vain... As Mr T keeps harping on about.. The code is portable... Pic 16 - 18 - 24 - 32 assembler are too different to port code from one to the other....You can!! but its harde than with C...
     
  6. nsaspook

    nsaspook Well-Known Member

    Joined:
    Mar 24, 2010
    Messages:
    1,141
    Likes:
    219
    Location:
    Fairview, Or
    An assembly expert could be just as fast but the assembly code needed for easy debugging at that level is usually not the assembly code needed for max efficiency so usually the expert starts writing the more efficient machine version first then adds debugging if needed that might change the efficient machine version structure of the program to fine tune the code, then the result is put back into a more efficient machine version again. With C the difference between the source version that generates the most abstract efficient machine version and the easily debugged source code version can usually be much closer with a good compiler.
     
  7. NorthGuy

    NorthGuy Well-Known Member

    Joined:
    Sep 8, 2013
    Messages:
    1,218
    Likes:
    206
    Location:
    Northern Canada
    I am a slow thinker. It takes me days to figure out how the program should work. And then it takes relatively short time to code. Probably would be faster to code in C ...

    I completely agree. That's what started the debate. If you go with Assembler, your code is not portable, sort of one-time shot. But then look at Linux software. It is portable. I guess, you still can compile and use some of the packages that were written 20 years ago (perhaps with little modifications). But look, most packages were re-written or replaced with new ones. Perhaps if you don't have anything portable, it'll force to write newer, better programs 10 years from now rather than adopting your old programs to the ever changing world?

    Were are programs that I wrote 30 years ago? They're in the dust. But back then I wanted my programs to be portable and reuseable. I had little packs of punch cards which were supposed to help me write better programs using my favorite PL/1 throughout my entire life. They were very well organized and I kept them in the shoe boxes with nice labels, so that I could find them easily. Where are they now? In the dust. I don't think I could write something using PL/1 now. My preparedness for the future only helped me to stay longer in the past because I din't want to take parts with my favorite PL/1 for way longer than I should've had. Very few people know what is PL/1 and how to use punch cards. 30 years from now, who will ever rememver that there used to be primitive embedded devices called MCUs?
     
    • Like Like x 1
  8. nsaspook

    nsaspook Well-Known Member

    Joined:
    Mar 24, 2010
    Messages:
    1,141
    Likes:
    219
    Location:
    Fairview, Or
    For me knowing all the gritty individual details of every language is not what's important. I once was very good at Modula-2, forth and several other 'dead' languages. The details of those languages are mainly gone from my head but the patterns and structures used in those languages are still there.

    Was never a PL/1 programmer but I was pretty good at punching up a FORTRAN deck for a batch job on several of the old AUTODIN network systems I once worked on.
    http://www.jproc.ca/crypto/autodin.html
     
  9. NorthGuy

    NorthGuy Well-Known Member

    Joined:
    Sep 8, 2013
    Messages:
    1,218
    Likes:
    206
    Location:
    Northern Canada
    Exactly. I agree 100%. There's no reason to get "married" to a particular language. You can learn programming with any language and then use your skills to write in any language that you (or your boss :) ) find suitable at a time and place.
     
    • Like Like x 1
  10. 3v0

    3v0 Coop Build Coordinator Forum Supporter

    Joined:
    Jul 14, 2006
    Messages:
    9,404
    Likes:
    227
    Location:
    OKLAHOMA USA
    We were talking about the possibility of creating structured code in asm. I simply pointed out that it is possible because compilers do so, with the condition that we turn off all optimization. It only proves the point that the compiler can generate structured asm which should not be a supprise to anyone. If the compiler can, then it is possible for humans to do so too. Heck just look at the asm output for debugging in mplab (or your favorite source level debugger) and one can see it in action.

    A good optimizer can tighten up the code more then the asm programmer because the optimized code does not have to be transparent to humans. To a degree the tightness of asm is myth and has been for decades. And yes there are bad compilers that generate way too much code. There are also lousy asm programmers. The free versions of the microchip compilers are anything but tight. But it is a heck of a lot cheaper to spend 50 cents or a buck extra to get more memory then to buy a two or five grand compiler.
     
    Last edited: Dec 6, 2013
  11. atferrari

    atferrari Well-Known Member

    Joined:
    Oct 8, 2003
    Messages:
    2,812
    Likes:
    121
    Location:
    Buenos Aires - Argentina
    Wow! Never seen this put in writing. You got me thinking...
     
  12. killivolt

    killivolt Well-Known Member

    Joined:
    Mar 12, 2008
    Messages:
    3,212
    Likes:
    121
    Location:
    U.S.
    I believe this is an interesting thought. I've thought about it, but never could put it to words.

    Edit: I keep telling people I'm analog not digital. I was ok, with 1v peak to peak. But, now it's packets?

    Edit: Edit: I didn't have time to write what I mean, after re-reading. I mean with Audio and Video, Analog Video vs Digital, I have to change my way of thinking.

    NorthGuy, this looks like a good signature:rolleyes:
     
    Last edited: Dec 9, 2013

Share This Page