Solved

Error in bitwise OR operation?

Posted on 2004-07-30
4
176 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
  • 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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Summary: This tutorial covers some basics of pointer, pointer arithmetic and function pointer. What is a pointer: A pointer is a variable which holds an address. This address might be address of another variable/address of devices/address of fu…
This is a short and sweet, but (hopefully) to the point article. There seems to be some fundamental misunderstanding about the function prototype for the "main" function in C and C++, more specifically what type this function should return. I see so…
Video by: Grant
The goal of this video is to provide viewers with basic examples to understand and use for-loops in the C programming language.
The goal of this video is to provide viewers with basic examples to understand and use conditional statements in the C programming language.

828 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