Irrelevant, as I rarely read *any* post from him
So, when I call bullshit it is simply because this time I did
Irrelevant, as I rarely read *any* post from him
So, when I call bullshit it is simply because this time I did
Everyone writes code "their own way", even with formal coding standards in place.
Magic numbers are poor coding practice, period. Why aren't you having a word or three with them - or their management?
Neat trick. So, if you need to write something to, say, port 39 how do you do it without encoding the number 39 somewhere?
It would be like writing an "Ezekiel" program without somewhere having the string "fsckwit".
-- 'What about all of the claims of how OpenOffice can seamlessly open up Word and Excel documents often better than MS Office. I suppose that was just another "advocate" lie.' - trolling fsckwit "Ezekiel"
I'm certain that a pretender like "7" has no idea. Here's one simple way it could be done:
const char* port_name = "LED_OUTPUT_PORT";
if(getenv(port_name)) port_num = strtoul( getenv(port_name), NULL, 10); else port_num = get_value_from_config_file(port_name);
I did - did you not read paragraph below?
That depends. On an average day there would no reason to write 39 to anything and would probably be meaningless in different context. It must serve a purpose. So I would write it this way to prevent 39 being hard coded into even bit of follow up code.
#define SEND_SYSTEM_RESET_CODE 39 #define HELP_MESSAGE_39 39 ..
Then why don't you follow your own advise and what you claim to have spec'd out?
#define LED_ON 1 #define LED_OFF 0
main() { LED_Register.All_LEDs = 0; // All LEDs off - directly write to all LEDs
According to your own blabbering... this should be:
main() { LED_Register.All_LEDs = LED_OFF; // All LEDs off....
That way you *hardcode* the number into the executeable. Just because you use a #define does not mean that any code has been changed You just get to change the value easier before compiling, and it makes it less error prone if the value is used at several places.
The only way *not* to hardcode any value is by reading it in via some means. You still can have a hardcoded value in the binary, as long as you have some means of overriding it during runtime without changing the binary
Your "way to avoid hardcoding" is bollocks and unworthy of a real programmer
Ewwww! Don't do that.
Ewww! Don't do that either.
NACKed.
Phil
-- > I'd argue that there is much evidence for the existence of a God. Pics or it didn't happen. -- Tom (/. uid 822)
By all means save us the laughs and write one line of code to say what you would do.
By all means save us the laughs and write one line of code to say what you would do.
Well, even the mindless robotic conversion to
#define ENABLE_RS232_INTERRUPT() do { SYSCON.INT.INT_XMA = ENABLED; } while(0)
would be better than what you had.
Phil
-- > I'd argue that there is much evidence for the existence of a God. Pics or it didn't happen. -- Tom (/. uid 822)
I would prefer three lines:
static inline void enable_rs232_interrupt(void) { SYSCON.INT.INT_XMA = ENABLED; }
Be daring - learn C99!
? Speaking of "#define" macros... #define While( Should_Loop ) Ch = 1, P-- ; \ while( Ch?1 = Ch, Ch && ( Ch = *++P, Ch2 = !Ch ? 0 : P[1], Should_Loop ) )
wchar_t B[] = L"hello world", *P = B, Ch?1, Ch, Ch2 ; // Capitalise B, make it "Hello World". While( Ch ) if ( Ch?1
while(0)
Whilst it is a sensible assumption to presume that SYSCON is visible at the point of definition of the helper, it is by no means guaranteed, as it's not obvious from the above, nor necessary for the macro to work - you have to bear in mind the kind of code we're already dealing with.
I'd rather not have to forget the C11 things, thank you.
Phil
-- > I'd argue that there is much evidence for the existence of a God. Pics or it didn't happen. -- Tom (/. uid 822)
Pics or it didn't happen.
-- Tom (/. uid 822)
Waaaat?
Lets say you define all the hardware in hardware.h. Then at the beginning you do this:
#ifndef HARDWARE_H #define HARDWARE_H // filename hardware.h
#include "your_CPU's_CMSIS_header_file.h"
#define ENABLED 1 #define ENABLE_RS232_INTERRUPT SYSCON.INT.INT_XMA = ENABLED
// end of hardware.h #endif
Now whenever you do a include "hardware.h" to get at ENABLE_RS232_INTERRUPT, you automatically have access to whatever SYSCON has been set up as in the CMSIS file.
So far so good. Seems a reasonable start. Tho I don't know what is inside the CMSIS header file.
The mere fact that you've felt it necessary to now provide a fuller example clearly reinforces my point that what you posted earlier was capable of being in a context where the change to a function might not compile. If you can't understand why, then you need to learn a bit more about C and its preprocessor.
Phil
-- > I'd argue that there is much evidence for the existence of a God. Pics or it didn't happen. -- Tom (/. uid 822)
You should first try explaining that to the man in the mirror.
I'm sure he understands exactly what was written. It's *you* who's the clueless moron pretending to be a software engineer.
-- Another documented lie from the trailer trash "chrisv" turd - "Well, according to monopoly-supporting fsckheads like "Ezekiel" and "Hadron", OEM's should only ship the one OS on everything, to avoid "confusion". MsgID: u532l7tud4bq1v76sok3bk7fugriin3js3@4ax.com March 2, 2012
ElectronDepot website is not affiliated with any of the manufacturers or service providers discussed here. All logos and trade names are the property of their respective owners.