Yahoo Groups archive

Lpc2000

Index last updated: 2026-04-28 23:31 UTC

Thread

Good C code

Good C code

2006-05-05 by jk jlkj

Hi Friends,
   
  Did anyone came accross such a code.
   
  INT32U is unsigned int.
   
  #define  BSP_UNDEF_INSTRUCTION_VECTOR_ADDR   (*(INT32U *)0x00000004L)
   
  I really think this is a neat code. This is in the code given by ucos-ii. 
  Isnt this similar to declaring a pointer variable.
   
  I am unable to understand the meaning of the type cast (*(INT32U *))
   
  Can some one please tell me what does this type cast imply.
   
  Regards,
  Jerome
   
   

				
---------------------------------
 Yahoo! India Answers: Share what you know. Learn something new. Click here

[Non-text portions of this message have been removed]

Re: Good C code

2006-05-05 by brendanmurphy37

Hi,

There's two things going on here.

1. INT32U is being used as a short-hand for "unsigned int". There are 
two reasons I can think for defining this: (a) its quicker and 
simpler to write and, more importantly, (b) if the definition is in 
an include file, the file can be constructed or altered to suit 
different platforms. Thus on some platforms INT32U might be defined 
as "unsigned long int". Done this way, the main body of code doesn't 
have to change: if you want an unsigned 32-bit integer, you just use 
the defined type "INT32U". By the way, using upper case as a type 
name is a somewhat old practice (derived from using MACROs to define 
types before "typedef" was part of the langaue).

2. The construct "(*(INT32U *) VALUE)" is a very common way of 
enabling a constant integer value to be used as an address (i.e. 
pointer) type. The "(INT32U *) VALUE" part says "treat VALUE as 
a "pointer to an unsigned int". The extra "*" then says de-reference 
this pointer. It lets you write code like:

BSP_UNDEF_INSTRUCTION_VECTOR_ADDR = 0;

This stores the value 0 at the address 0x00000004.

A variation on this is to define a MACRO such as:

#define REG(addr) (*(volatile unsigned int *)(addr))

You can use this like:

#define VICIntEnable (0xFFFFF010)

REG(VICIntEnable) = 0x40;

Brendan

--- In lpc2000@yahoogroups.com, jk jlkj <njad2002@...> wrote:
>
> Hi Friends,
>    
>   Did anyone came accross such a code.
>    
>   INT32U is unsigned int.
>    
>   #define  BSP_UNDEF_INSTRUCTION_VECTOR_ADDR   (*(INT32U *)
0x00000004L)
>    
>   I really think this is a neat code. This is in the code given by 
ucos-ii. 
>   Isnt this similar to declaring a pointer variable.
>    
>   I am unable to understand the meaning of the type cast (*(INT32U 
*))
>    
>   Can some one please tell me what does this type cast imply.
>    
>   Regards,
>   Jerome
>    
>    
> 
> 				
> ---------------------------------
>  Yahoo! India Answers: Share what you know. Learn something new. 
Click here
Show quoted textHide quoted text
> 
> [Non-text portions of this message have been removed]
>

Re: [lpc2000] Good C code

2006-05-05 by vineet jain

Hi,
 To put simply:

Say for example:

unsigned int *ram_ptr  =  ( unsigned int * ) 0x000000F0;
So, to store something at this address you would write something like:

*ram_ptr  = 36;

The above statement means that ram_ptr is pointing to memory location 0x000000F0.

Now when you write 

BSP_UNDEF_INSTRUCTION_VECTOR_ADDR   (*(INT32U *)0x00000004L)

it means BSP_UNDEF_INSTRUCTION_VECTOR_ADDR is the content of the memory address 0x00000004L.
Here to store a value at the 0x00000004L address you would write 

BSP_UNDEF_INSTRUCTION_VECTOR_ADDR = 36;


Vineet.


jk jlkj <njad2002@...> wrote:    Hi Friends,
    
   Did anyone came accross such a code.
    
   INT32U is unsigned int.
    
   #define  BSP_UNDEF_INSTRUCTION_VECTOR_ADDR   (*(INT32U *)0x00000004L)
    
   I really think this is a neat code. This is in the code given by ucos-ii. 
   Isnt this similar to declaring a pointer variable.
    
   I am unable to understand the meaning of the type cast (*(INT32U *))
    
   Can some one please tell me what does this type cast imply.
    
   Regards,
   Jerome
    
    
 
                         
 ---------------------------------
  Yahoo! India Answers: Share what you know. Learn something new. Click here
 
 [Non-text portions of this message have been removed]
 
            

        SPONSORED LINKS   
                                                    Microcontrollers                                       Microprocessor                                       Intel microprocessors                                                                 
      
---------------------------------
   YAHOO! GROUPS LINKS 
 
    
    Visit your group "lpc2000" on the web.
    
    To unsubscribe from this group, send an email to:
 lpc2000-unsubscribe@yahoogroups.com
    
    Your use of Yahoo! Groups is subject to the Yahoo! Terms of Service. 
 
    
---------------------------------
 
 
     

			
---------------------------------
Yahoo! Mail goes everywhere you do.  Get it on your phone.

[Non-text portions of this message have been removed]

Move to quarantaine

This moves the raw source file on disk only. The archive index is not changed automatically, so you still need to run a manual refresh afterward.