Author Topic: [C preprocessor]  (Read 2003 times)

0 Members and 1 Guest are viewing this topic.

Offline Simon

  • Global Moderator
  • *****
  • Posts: 14038
  • Country: gb
  • Did that just blow up? No? might work after all !!
    • Simon's Electronics
Re: [C preprocessor]
« Reply #25 on: August 04, 2018, 09:16:11 am »
I simply use defines to make the code readable by replacing text as shown above. The new register names make a little more sense but with thing that require multiple bits I get fed up with looking them up so I just define what i want to do and it is replaced by the code.
https://www.simonselectronics.co.uk/shop
Varied stock of test instruments and components including EEVblog gear and Wurth Elektronik Books.
Also, if you want to get ripped off: https://www.ebay.co.uk/usr/simons_electronics?_trksid=p2047675.l2559
 

Online tggzzz

  • Super Contributor
  • ***
  • Posts: 10472
  • Country: gb
    • Having fun doing more, with less
Re: [C preprocessor]
« Reply #26 on: August 04, 2018, 09:27:58 am »
As I've found just this week... forget a return statement in a small function. Looked at assembly output; half of my program was gone. Turns out, newer GCC revisions could choose to not generate code at all for a statement with undefined behaviour, and all surrounding bits of that code. Nice try finding that, but also more reasons not to write crap code quickly.

You are lucky. You couldn't have objected if it chose to "rm -rf /", or cause demons to fly out from your nose :)
There are lies, damned lies, statistics - and ADC/DAC specs.
Glider pilot's aphorism: "there is no substitute for span". Retort: "There is a substitute: skill+imagination. But you can buy span".
Having fun doing more, with less
 
The following users thanked this post: newbrain

Offline Simon

  • Global Moderator
  • *****
  • Posts: 14038
  • Country: gb
  • Did that just blow up? No? might work after all !!
    • Simon's Electronics
Re: [C preprocessor]
« Reply #27 on: August 04, 2018, 09:42:36 am »
As I've found just this week... forget a return statement in a small function. Looked at assembly output; half of my program was gone. Turns out, newer GCC revisions could choose to not generate code at all for a statement with undefined behaviour, and all surrounding bits of that code. Nice try finding that, but also more reasons not to write crap code quickly.

You are lucky. You couldn't have objected if it chose to "rm -rf /", or cause demons to fly out from your nose :)

Err, I was made to put return statements in functions as CCC threw a wobbly and insisted. Mainly on interrupt functions.
https://www.simonselectronics.co.uk/shop
Varied stock of test instruments and components including EEVblog gear and Wurth Elektronik Books.
Also, if you want to get ripped off: https://www.ebay.co.uk/usr/simons_electronics?_trksid=p2047675.l2559
 

Online tggzzz

  • Super Contributor
  • ***
  • Posts: 10472
  • Country: gb
    • Having fun doing more, with less
Re: [C preprocessor]
« Reply #28 on: August 04, 2018, 10:09:58 am »
As I've found just this week... forget a return statement in a small function. Looked at assembly output; half of my program was gone. Turns out, newer GCC revisions could choose to not generate code at all for a statement with undefined behaviour, and all surrounding bits of that code. Nice try finding that, but also more reasons not to write crap code quickly.

You are lucky. You couldn't have objected if it chose to "rm -rf /", or cause demons to fly out from your nose :)

Err, I was made to put return statements in functions as CCC threw a wobbly and insisted. Mainly on interrupt functions.

"undefined behaviour" can cause "nasal demons". But I'm sure you know that.
There are lies, damned lies, statistics - and ADC/DAC specs.
Glider pilot's aphorism: "there is no substitute for span". Retort: "There is a substitute: skill+imagination. But you can buy span".
Having fun doing more, with less
 

Offline hans

  • Super Contributor
  • ***
  • Posts: 1044
  • Country: nl
Re: [C preprocessor]
« Reply #29 on: August 04, 2018, 10:11:42 am »
Very funny.
 

Online tggzzz

  • Super Contributor
  • ***
  • Posts: 10472
  • Country: gb
    • Having fun doing more, with less
Re: [C preprocessor]
« Reply #30 on: August 04, 2018, 10:34:56 am »
Very funny.

"Many a truth is spoken in jest". The underlying problem isn't funny, unfortunately!
« Last Edit: August 04, 2018, 12:58:52 pm by tggzzz »
There are lies, damned lies, statistics - and ADC/DAC specs.
Glider pilot's aphorism: "there is no substitute for span". Retort: "There is a substitute: skill+imagination. But you can buy span".
Having fun doing more, with less
 

Offline andyturk

  • Frequent Contributor
  • **
  • Posts: 892
  • Country: us
Re: [C preprocessor]
« Reply #31 on: August 07, 2018, 02:37:10 am »
I'd rather use language/compiler features for constants, "inline" functions, and abstractions intended to make code more portable.

Would you use C++ templates to compute the sequence of prime numbers during compilation? (Naturally the compilation can never finish!)
Example: https://en.wikibooks.org/wiki/C%2B%2B_Programming/Templates/Template_Meta-Programming#History_of_TMP
Would I? Yeah, probably. But I've never actually needed to do that (yet). I did look at some TMP code that generated a constexpr trig lookup table at compile-time, which was very cool and far better (IMO) than a two-stage build with a code generator that spit out some C source to be compiled in the next phase.

Quote
[... macros]

Yes, we all use them.
Yes, we've all been infuriated by other people's use of them.

So, how about m4? It makes the C preprocessor look rather toy-like. And m4 was also designed by K&R.  >:D
 
The following users thanked this post: hans


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf