This is the mail archive of the ecos-discuss@sources.redhat.com mailing list for the eCos project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: initializing cyg_handle_t values before passing to a function


On Thu, Aug 07, 2003 at 03:55:49PM -0400, Aaron Case wrote:
> Hi,
> 
> I was wondering what happens when I declare a cyg_handle_t variable, the
> best that I can see from the eCos code is that it is a simple typedef.

Correct.

> 
> Yet, in the case of cyg_alarm_create(), several of these cyg data
> types(cyg_hanlde_t, cyg_alarm_t,cyg_alarm) are pass without being
> initialized.

Not quite right:

void cyg_alarm_create(cyg_handle_t counter, cyg_alarm_t* alarmfn, cyg_addrword_t data,
cyg_handle_t* handle, cyg_alarm* alarm);

There are lots of address of passed, not values. The first has to be initialised, its
the handle of the counter you want to attach this alarm to. Normaly you use the counter 
for the real time clock. You can get this with a combination of cyg_real_time_clock 
and cyg_clock_to_counter.

alarmfm is the address of a function. You could have a variable containing a functiom
pointer, but normally you just pass the function. The second handle pointer will be
filled in by this function. Its a handle for the alarm you are creating. Even if you
did initialise it, it will get stomped over during this call. The last, cyg_alarm is
the storage space eCos needs for the alarm. The design of eCos is that the kernel does
not use dynamically allocated memory. You the programmer have to explicity allocate it
and pass it to the create function. eCos then remembers it for all further calls.
 
> So my question is, when I declare cyg_handle_t what happens besides
> declaring the data type set by the typdefs in kapi.h and system.h.

Nothing. Nothing could happen. This is C. The language C does not have constuctors
like C++ does. 

	Andrew

-- 
Before posting, please read the FAQ: http://sources.redhat.com/fom/ecos
and search the list archive: http://sources.redhat.com/ml/ecos-discuss


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]