Embedded / RTOS

Moderators: None (Apply to moderate this forum)
Number of threads: 347
Number of posts: 650

This Forum Only
Post New Thread
Single Post View       Linear View       Threaded View      f

Report
C and embedded Posted by askembc on 3 Nov 2009 at 12:02 AM
#include <stdio.h>
#include <conio.h>
#define RW 0
#define write() RW|=1
int main()
{
printf("Before \n%d",RW);
write();
printf("After calling WRITE \n%d",RW);
getch();
return 0;
}

Hi all

Iam new to embedded programming with C
In the above program Iam trying to modify a macro with #define
Its not working
Please tell me where I went wrong
Report
Re: C and embedded Posted by allskyline on 5 Nov 2009 at 6:24 AM
hi,
Because RW is a macro define, its value can't be changed. In your program, define write() with RW |= 1, and when this program is compiled, write() will be replaced with 0 |= 1, it is impossible.
if you want to change the value of RW, you can use this:
#include <stdio.h>

static unsigned int RW = 0;

__inline write()
{
RW |= 1;
}

int main()
{
printf("Before \n %d", RW);
write();
printf("After calling WRITE \n %d", RW);
getchar();

return 0;
}

http://www.coocox.org/CooCox_Builder.htm
a completely free and highly automatical integrated development environment for the application based on ARM Cortex M3




 

Recent Jobs

Official Programmer's Heaven Blogs
Web Hosting | Browser and Social Games | Gadgets

Popular resources on Programmersheaven.com
Assembly | Basic | C | C# | C++ | Delphi | Flash | Java | JavaScript | Pascal | Perl | PHP | Python | Ruby | Visual Basic
© Copyright 2011 Programmersheaven.com - All rights reserved.
Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
Operated by CommunityHeaven, a BootstrapLabs company.