Solved

Error in bitwise OR operation?

Posted on 2004-07-30
4
179 Views
Last Modified: 2010-04-15
I am getting an error for the following code...

 #include<stdio.h>
#include<stdlib.h>
#include <string.h>

#define hex 0x00020000;
void main()
{
      unsigned r;
       r=hex | 100;
      printf("%u",r);
      getchar();
}

error C2143: syntax error : missing ';' before '|'

What is the problem?

0
Comment
Question by:gopikrish
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 55

Accepted Solution

by:
Jaime Olivares earned 30 total points
ID: 11681739
Hi gopikrish,
> #define hex 0x00020000;
the last comma is not valid. Would be:
#define hex 0x00020000

Good luck,
Jaime.
0
 
LVL 55

Expert Comment

by:Jaime Olivares
ID: 11681749
To be clearer: #defines don't need an ending colon (;) like regular C code lines.
0
 
LVL 5

Expert Comment

by:ddunlea
ID: 11682033
Whilst it's not causing the problem you're seeing, are you sure you want to be ORing decimal 100 i.e. 0x64? You probably want to write 0x100, which will give you a single bit set high,  as opposed to just plain 100 which will give 01100100b
0
 
LVL 23

Expert Comment

by:Mysidia
ID: 11682715
Since you have
 #define hex 0x00020000;

The line:
       r=hex | 100;

is actually expanding to
        r=0x00020000; | 100;

Which is not what you want: "| 100;"  is not a valid C statement
Removing the trailing semicolon in the #define hex   line should remedy this
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This tutorial is posted by Aaron Wojnowski, administrator at SDKExpert.net.  To view more iPhone tutorials, visit www.sdkexpert.net. This is a very simple tutorial on finding the user's current location easily. In this tutorial, you will learn ho…
Windows programmers of the C/C++ variety, how many of you realise that since Window 9x Microsoft has been lying to you about what constitutes Unicode (http://en.wikipedia.org/wiki/Unicode)? They will have you believe that Unicode requires you to use…
The goal of this video is to provide viewers with basic examples to understand how to create, access, and change arrays in the C programming language.
The goal of this video is to provide viewers with basic examples to understand and use switch statements in the C programming language.

617 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question