473,399 Members | 4,254 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,399 software developers and data experts.

spot the bug

I've been working around a sample program thats "suppose" to work,
according to Herbert Schildt-but it doesn't... I'm getting a
redefinition error from struct byte. anyone know whats wrong and how
to fixit? and i need some indepth tutorials about bitwise operators
and bitfield.
struct byte
{
unsigned a : 1;
unsigned b : 1;
//... all the way to unsigned h : 1;
};

union bits
{
char ch;
byte bit;
} ascii; //this program displays the ascii code in binary for
characters

void disp_bits(bits b); /*contains code like if(b.bit.h) cout<<"1 "l;
else cout<<"0 "; */

int main()
{
do
{
cin>>ascii.ch;
cout<<": ";
disp_bits(ascii);
}while(ascii.ch!='q');
return 0;
}
Jul 19 '05 #1
3 2860
On 12 Jul 2003 07:36:11 -0700, sa********@yahoo.co.uk (urocrane) wrote:
I've been working around a sample program thats "suppose" to work,
according to Herbert Schildt-but it doesn't...
See the FAQ on (I think it was) alt.learn.c or whatever
group it was, about Schildt's books. Upshot: nearest trash can.
However, this particular problem doesn't seem to be due to him.

I'm getting a
redefinition error from struct byte. anyone know whats wrong and how
to fixit?
The code as presented in your posting is technically OK.

Perhaps your compiler objects to the identifier 'byte'.

and i need some indepth tutorials about bitwise operators
and bitfield.


See the C++ FAQ for suggestions about literature.

Jul 19 '05 #2

"urocrane" <sa********@yahoo.co.uk> wrote in message
news:b3**************************@posting.google.c om...
I've been working around a sample program thats "suppose" to work,
according to Herbert Schildt-but it doesn't... I'm getting a
redefinition error from struct byte. anyone know whats wrong and how
to fixit? and i need some indepth tutorials about bitwise operators
and bitfield.
struct byte
{
unsigned a : 1;
unsigned b : 1;
//... all the way to unsigned h : 1;
};

union bits
{
char ch;
byte bit;
} ascii; //this program displays the ascii code in binary for
characters

void disp_bits(bits b); /*contains code like if(b.bit.h) cout<<"1 "l;
else cout<<"0 "; */

int main()
{
do
{
cin>>ascii.ch;
cout<<": ";
disp_bits(ascii);
}while(ascii.ch!='q');
return 0;
}


Your compiler may not like "byte." Some compilers have a built-in type byte,
and thus you would be redefining that keyword. Then again, some nonstandard
libraries define byte on their own, so that could be a problem. As your
compiler is saying that byte is being redefined, it seems that it is not a
keyword. You've probably got some library that's defining byte on its own.
Ensure only standard libraries:

This Should be changed to
#include <iostream.h> #include <iostream>
using namespace std;
#include <conio.h> Nothing. do not use it.
#include <fstream.h> #include <fstream>
using namespace std;

Note that you only say "using namespace std;" once.

--
MiniDisc_2k2
Jul 19 '05 #3
"urocrane" <sa********@yahoo.co.uk> wrote in message
news:b3**************************@posting.google.c om
I've been working around a sample program thats "suppose" to work,
according to Herbert Schildt-but it doesn't... I'm getting a
redefinition error from struct byte. anyone know whats wrong and how
to fixit? and i need some indepth tutorials about bitwise operators
and bitfield.
struct byte
{
unsigned a : 1;
unsigned b : 1;
//... all the way to unsigned h : 1;
};

union bits
{
char ch;
byte bit;
} ascii; //this program displays the ascii code in binary for
characters

void disp_bits(bits b); /*contains code like if(b.bit.h) cout<<"1 "l;
else cout<<"0 "; */

int main()
{
do
{
cin>>ascii.ch;
cout<<": ";
disp_bits(ascii);
}while(ascii.ch!='q');
return 0;
}

Does your compiler error message tell you where byte is first defined? Mine
does. Clicking on the error message takes me to "RpcNdr.h", which is a file
included when I include "windows.h". Your problem will be similar, if not
identical.

--
John Carson
1. To reply to email address, remove donald
2. Don't reply to email address (post here instead)

Jul 19 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: sumGirl | last post by:
Hi all. I am looking for a script that I might use to spot OS, hardware, registry changes. Also be nice if I could tell when someone loads new software or unistalls old, by I guess I would see that...
2
by: Murray J | last post by:
I have an HTML page which is an image map with a 4 X 4 grid of 'hot spots', linking to other HTML pages, each of which contains a large (3200px X 2560px) image. I would like to capture the...
3
by: JKop | last post by:
I have some code which when compiled on my system prints: <output> AnyClass Constructor for: blah AnyClass Copy Constructor for: Copy of blah AnyClass Copy Constructor for: Copy of Copy...
2
by: Jacob Kjaergaard | last post by:
Hi! Im looking for a (relatively) easy way to print at the same spot on the terminal. Like i.e wget does when showing the progressbar and the percentage of the download. if been looking in...
1
by: antipode | last post by:
That's about it. If I make a cursor of any size and color depth, the button to set the hot spot stays disabled. I'm at my wit's end, and yet I know it's got to be something stupid I'm missing.
0
by: gregory_may | last post by:
I apologize for cross posting, but I don't know the best place to post this. This link is a pretty good overview of the various System Cursor routines....
1
by: Tshepang Lekhonkhobe | last post by:
Hi, I dislike installing the entire Mono stack simply to take notes and manage photos, and am totally biased towards Python. At least for search I got Tracker, instead of Beagle. Are there...
2
by: eloi-ribeiro.blogspot.com | last post by:
Hi, I'm having a problem with a query. I'm running Access 2000 and a table with 35000 rows. The table contains several visits to the spots with a CODE (spot code) and DATE (visit date)...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.