Re: "PORTING C" > How to assign a value to a define statement?
Robby <Robby@discussions.microsoft.com> wrote:
"Igor Tandetnik" wrote:
#define extCrys 8
#define fpllidiv 2
#define fpllmul 21
#define fpllodiv 8
#define FREQ
(((float)(extCrys/fpllidiv)*(float)(fpllmul/fpllodiv))*1000000)
Igor, one thing though, I am trying to create structures that hold
only one type of data which relates to one type of task in my code.
Then I would like to create functions that would manipulate the
respective structure accordingly.
Well, if they are compile-time constants, what precisely does it mean to =
"manipulate" them?
So for example, if I am setting up
a #define statement to hold the current system clock... like this:
#define extCrys 8
#define fpllidiv 2
#define fpllmul 21
#define fpllodiv 8
#define
=
CURR_SYS_OSC(((float)(extCrys/fpllidiv)*(float)(fpllmul/fpllodiv))*100000=
0)
I would rather create a structure holding this type of data. Then
call a function to manipulate it. I think!!!
So, forget about implementation details. Design the interface from the =
client's point of view: if you somehow magically had a thrid-party =
library of your dreams doing precisely what you want to do, what would =
that library's API look like? What calls would you make to it? Then, =
once you have your ideal interface, fill in the implementation.
So what I am saying is, that, isn't there a better and more
structured way of doing...
Perhaps. It's hard for me to say, as I have no idea what it is you are =
trying to achieve. Now, before you go and write a long explanation, note =
that I'm probably not going to read it: except in very simple and =
obvious cases, it takes too much effort to understand the problem well =
enough to offer a good design, so as a rule, I don't give design advice.
Mind you, one thing that doesn't help here is
that I am a little confused as what is the difference between an API
call *and* a normal function call
None. API is just a collection of functions, usually designed to work =
together and united by a common theme. An "API call" is just a shorthand =
for "a call to a function from some API" (it is usually clear from =
context which API is meant).
*and* when we create an object and
call a function passing a pointer to the object as a parameter.
I don't know of any special name for this technique. It's a function =
call like any other.
--
With best wishes,
Igor Tandetnik
With sufficient thrust, pigs fly just fine. However, this is not =
necessarily a good idea. It is hard to be sure where they are going to =
land, and it could be dangerous sitting under them as they fly overhead. =
-- RFC 1925