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: programming technic about the macro?


On Mon, 2002-10-28 at 15:12, Qiang Huang wrote:
> Hi all:
>     I have looked into the IO support function and found the following:
> 
> for example(ARM):
> 
> #define HAL_READ_UINT16_STRING( _register_, _buf_, _count_)             \
>     CYG_MACRO_START                                                     \
>     cyg_count32 _i_;                                                    \
>     for( _i_ = 0; _i_ < (_count_); _i_++)                               \
>         (_buf_)[_i_] = ((volatile CYG_WORD16 *)(_register_))[_i_];      \
>     CYG_MACRO_END
> 
> 
> in the macro the tempory variable **_i_** has been declared, so if this
> macro has been called twice inside one function will it cause any variable
> redefinition (_i_)  problem?e.g.
> 
> main()
> {
>    HAL_READ_UINT16_STRING();
>    HAL_READ_UINT16_STRING();
> }
> 

No - look more carefully and you'll see that CYG_MACRO_START generates
an opening brace "{" and CYG_MACRO_END a closing brace "}".  So the
HAL_READ_UINT16_STRING macro defines a separate scope for "_i_"

-- 
------------------------------------------------------------
Gary Thomas                  |
eCosCentric, Ltd.            |  
+1 (970) 229-1963            |  eCos & RedBoot experts
gthomas@ecoscentric.com      |
http://www.ecoscentric.com/  |
------------------------------------------------------------


-- 
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]