c programming help,preprocessor

Status
Not open for further replies.

dizgah

Member level 5
Joined
Nov 8, 2009
Messages
91
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,286
Location
iran-8par
Visit site
Activity points
2,049
hi every body
what does this code do ?
Code:
#define k1 [B]((uint16_t)0x0000)[/B]
im familiar with duty of define preprocessor instruction,but i dont know what does bold section do.
tnks

- - - Updated - - -

my second question is:
Code:
void SPI_Init(SPI_TypeDef* SPIx, SPI_InitTypeDef* SPI_InitStruct)
in above function why we declare input variable in this method ,and dont declare usual like:
Code:
voide m1(int1,int2);
tnks again
 

#define creates as macro.

In the line mentioned
#define k1 ((uint16_t)0x0000)

A simple k1 can be used in a code when ever ((uint16_t)0x0000) is used.

Using this identifier the code can be made readable.

I would prefer to you something more readable Identifier than k1.
 
Reactions: dizgah

    dizgah

    Points: 2
    Helpful Answer Positive Rating
tnks i know, k1 was only for example
as i said i know function of define preprocessor ,my ques is what does
Code:
((uint16_t)0x0000)
do ?
as i know that say declare k1 equal with 0x0000 and 0x0000 is a 2byte size variable(unsigned int ),am i true?
then why we dont write
Code:
 #define k1 0x0000
cant compiler know size of constant/var from number of digits?
and we say it to compiler with this method ?
--------------
whats my second ques answer ?
tnks
 

((uint16_t)0x0000)

With the above line you mention that it is a 16 bit value i.e 2Bytes.

You are typecasting the value to a 16bit where you have only assigned 4bits. Remaining bits are set to zero by type casting as above.

For second question :

There is a called function and calling function.
Called function : When one piece of code invokes or calls a function.
Example voide m1(int1,int2);
Calling funciton : When called by a function, this piece of code tells what needs to be done.
Example void SPI_Init(SPI_TypeDef* SPIx, SPI_InitTypeDef* SPI_InitStruct)

In the above calling function, SPI_TypeDef and SPI_InitTypeDef are defined in the code as structures. SPIx and SPI_InitStruct are initialised to create a temp value

SPIx. a = 123; SPIx.b = 456; ... etc.

In called function.. int1 and int2 initialized in main and are have a scope of using those variables in whole program. These two examples are not the perfect way to look at the called and calling function.

Hope am being clear .....
 
Reactions: dizgah

    dizgah

    Points: 2
    Helpful Answer Positive Rating
In

Code C - [expand]
1
SPI_Init(SPI_TypeDef* SPIx, SPI_InitTypeDef* SPI_InitStruct)



SPI_TypeDef* is a pointer to SPI_TypeDef type and SPI_InitTypeDef* is a pointer to SPI_InitTypeDef type.

SPIx and SPI_InitStruct are other two types of data types. They are defined else where in the code.

You have to post the full code for better answer.
 
Reactions: dizgah

    dizgah

    Points: 2
    Helpful Answer Positive Rating
Status
Not open for further replies.

Similar threads

Cookies are required to use this site. You must accept them to continue using the site. Learn more…