It is currently Thu Nov 23, 2017 5:23 pm

All times are UTC - 7 hours





Post new topic Reply to topic  [ 6 posts ] 
Author Message
 Post subject: C++: working with bits?
PostPosted: Thu Oct 20, 2016 12:37 pm 
Offline

Joined: Thu Oct 20, 2016 12:35 pm
Posts: 1
Hello,
I'm reading a 6502 programming book, and have decided to code every peice mentioned in the book, put it together and make it work.

so, i've got the boost libraries installed and am using 8 and 16 bit integer types. but i can't measure them( sizeof() only measures in bytes ) and i don't know how i can work with bits if i'm only measuring bytes.

anyone know of a solution to this? bi quyet lam giau

Code:
#include <iostream>
#include <boost/cstdint.hpp>

using namespace std;

int main()
{
   static const boost::int8_t   int8;
   cout << "sizeof(int8) = " << sizeof(int8) << endl;
    return 0;
}

_________________
dich vu thong cong nghet gia re thong cong nghet uy tin cong ty giup viec nha tphcm


Last edited by jonhsame on Mon Nov 07, 2016 10:01 am, edited 2 times in total.

Top
 Profile  
 
PostPosted: Thu Oct 20, 2016 3:41 pm 
Offline
User avatar

Joined: Fri Nov 19, 2004 7:35 pm
Posts: 3951
I don't think there are any 6502 C compilers powerful enough for C++, much less the highly complicated Boost library.

_________________
Here come the fortune cookies! Here come the fortune cookies! They're wearing paper hats!


Top
 Profile  
 
PostPosted: Thu Oct 20, 2016 3:52 pm 
Offline
User avatar

Joined: Sat Feb 12, 2005 9:43 pm
Posts: 10118
Location: Rio de Janeiro - Brazil
I don't really understand how C++ could have anything to do with a 6502 programming book... How/why do you intend to code things mentioned in a 6502 book in C++?


Top
 Profile  
 
PostPosted: Thu Oct 20, 2016 4:02 pm 
Offline
User avatar

Joined: Sun Jan 22, 2012 12:03 pm
Posts: 5837
Location: Canada
C++ does have bit fields, but whether or not they get stored efficiently is up to the compiler, and that's generally very spotty.
http://en.cppreference.com/w/cpp/language/bit_field

Because the bit field language feature leaves much to be desired, most people seem to pack bits manually, often using macros to make it more convenient.

As for 6502, I don't know much about trying to use C++ for 6502, but macro techniques for bit packing usually still work in C.


Top
 Profile  
 
PostPosted: Thu Oct 20, 2016 4:38 pm 
Offline
User avatar

Joined: Sun Sep 19, 2004 10:59 pm
Posts: 1393
rainwarrior wrote:
C++ does have bit fields, but whether or not they get stored efficiently is up to the compiler, and that's generally very spotty.
http://en.cppreference.com/w/cpp/language/bit_field

I'm pretty sure those are also available in plain C, though whether or not CC65 supports them is another question.

_________________
Quietust, QMT Productions
P.S. If you don't get this note, let me know and I'll write you another.


Top
 Profile  
 
PostPosted: Thu Oct 20, 2016 5:08 pm 
Offline
User avatar

Joined: Sun Jan 22, 2012 12:03 pm
Posts: 5837
Location: Canada
Oh, you're right. They're available in ANSI C. I guess I just assumed they were a later addition because of their obscurity. (I've almost never seen them used.)


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 6 posts ] 

All times are UTC - 7 hours


Who is online

Users browsing this forum: No registered users and 5 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB® Forum Software © phpBB Group