Solved

Error in bitwise OR operation?

Posted on 2004-07-30
4
172 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
Comment Utility
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
Comment Utility
To be clearer: #defines don't need an ending colon (;) like regular C code lines.
0
 
LVL 5

Expert Comment

by:ddunlea
Comment Utility
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
Comment Utility
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

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

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…
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…
The goal of this video is to provide viewers with basic examples to understand and use pointers in the C programming language.
Video by: Grant
The goal of this video is to provide viewers with basic examples to understand and use nested-loops in the C programming language.

743 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now