Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Error in bitwise OR operation?

Posted on 2004-07-30
4
Medium Priority
?
195 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 120 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

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

916 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