Solved

Error in bitwise OR operation?

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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
In C, why can't I shift a 64-bit integer more than 32 bits? 13 280
C++ vs C compilers 13 169
List out all word 7 359
C qsort compare function issue 6 70
An Outlet in Cocoa is a persistent reference to a GUI control; it connects a property (a variable) to a control.  For example, it is common to create an Outlet for the text field GUI control and change the text that appears in this field via that Ou…
Examines three attack vectors, specifically, the different types of malware used in malicious attacks, web application attacks, and finally, network based attacks.  Concludes by examining the means of securing and protecting critical systems and inf…
The goal of this video is to provide viewers with basic examples to understand and use structures 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.

752 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