ricardo ricardo

Casting function parameters C / C++

Discussion created by ricardo ricardo on Oct 26, 2009
Latest reply on Oct 27, 2009 by Daniel Lundin

Hy guys

I´m using  CW6.2 C++ in a QE128 design, wich is about my post here...

I also use CW 7.1 for ColdFires.

In ColdFires IDE I can cast a parameter in order it matches the expected struct, without the need of build such struct to pass it.

 

Example:

 

- THE STRUCT 

struct rtc_t

{

   uint8 day,month,year;

}

 

- THE FUNCTION

void cpu_rtc::write_rtc( rtc_t data )

{

   rtc_cpu.day=data.day;

   rtc_cpu.month=data.month;

   rtc_cpu.year=data.year;

}

 

- THE CALLING

1) This works: 

 

    rtc_t r={1,2,3};// init var rtc_t type

    write_rtc( r);  // pass expected type to the function

 

2) This ( the way I want ) doesn´t work: CW complains about wrong cast. 

 

     write_rtc( (rtc_t) {26,10,9});

 

It works in CW7.1 for ColdFires ( pure C ...I didn´t try C++ yet)

Its very practical, once we don´t need to formally create a struct to use as parameter.

 

I could not make it work in CW6.2 using C++ (maybe it dodesn´t work even in C.

 

Did I forget some small detail to accomplish it? 

Has anyone some experience like that?

 

Thanks everybody !!

 

Ricardo Raupp 

Outcomes