public inbox for ecos-discuss@sourceware.org
 help / color / mirror / Atom feed
* [ECOS] programming technic about the macro?
@ 2002-10-28 14:12 Qiang Huang
  2002-10-28 14:19 ` Gary Thomas
  2002-10-28 23:20 ` sandeep
  0 siblings, 2 replies; 3+ messages in thread
From: Qiang Huang @ 2002-10-28 14:12 UTC (permalink / raw)
  To: Ecos-Discuss

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();
}


Thank you.



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

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [ECOS] programming technic about the macro?
  2002-10-28 14:12 [ECOS] programming technic about the macro? Qiang Huang
@ 2002-10-28 14:19 ` Gary Thomas
  2002-10-28 23:20 ` sandeep
  1 sibling, 0 replies; 3+ messages in thread
From: Gary Thomas @ 2002-10-28 14:19 UTC (permalink / raw)
  To: Qiang Huang; +Cc: eCos Discussion

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

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [ECOS] programming technic about the macro?
  2002-10-28 14:12 [ECOS] programming technic about the macro? Qiang Huang
  2002-10-28 14:19 ` Gary Thomas
@ 2002-10-28 23:20 ` sandeep
  1 sibling, 0 replies; 3+ messages in thread
From: sandeep @ 2002-10-28 23:20 UTC (permalink / raw)
  To: Qiang Huang; +Cc: Ecos-Discuss

Hi Qiang,


> #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();
> }

There won't be any problem because in the code in question, the scopes of two 
_i_ are different.

if you look at packages/infra/current/include/cyg_type.h, you shall find --

#define CYG_MACRO_START do {
#define CYG_MACRO_END } while (0)


-- 
regards
sandeep
--------------------------------------------------------------------------
"My pants just went on a wild rampage through a Long Island Bowling
Alley!!"
		-- Zippy the Pinhead
--------------------------------------------------------------------------


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

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2002-10-29  7:20 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2002-10-28 14:12 [ECOS] programming technic about the macro? Qiang Huang
2002-10-28 14:19 ` Gary Thomas
2002-10-28 23:20 ` sandeep

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).