defining integers of arbitrary length?

Hi, all -

I need to simulate some 62-bit circuitry. I seem to remember reading somewhere about a C++ facility that lets me define integers of my own length, but my googling efforts found nothing useful. Can someone point me in the right direction?

Thanks.
You can use bitfields, but I'm not sure if it will go to 62-bits:

1
2
3
4
5
6
// my syntax might be rusty... but I think it's like this:

struct Foo
{
  int bar:62;
};
Thanks, Disch. I don't think they will either, plus it's my understanding that they're not very portable.

My original intention was to use 64-bit integers, but I'm not sure that's a good choice, either, since a value that would overflow a 62-bit field won't do the same to a 64-bit field.

I could swear that I read somewhere about defining integers of whatever length you wished...
closed account (zwA4jE8b)
i saw something like _int(n) where n is the size. But that is just a memory of something I was reading, might be worth checking out.
A bitfield or a bitset is the only way to do this AFAIK...

I have no idea what that _int(n) thing is.
CreativeMFS is probably thinking of __int8, __int16, etc. Those are non-standard compiler intrinsics built into Windows compilers, and they only work for sizes that the CPU natively handles (e.g. 8, 16, 32, and 64 on x86), not any length the programmer wants.

I'm fairly sure Disch's suggestion only works if the data type is large enough to contain all those bits, and an int probably isn't.

I'd suggest either an integer of guaranteed size, such as boost::uint64_t, a simple array of chars (how many bits each char will hold is not really important), or an std::vector<bool>. Which is best depends on what OP plans to do with the bits.
Thanks for the suggestions, guys. After more looking, I still can't find anything, so maybe I just dreamt it up. I think I'll just use the int64_t type that the compiler provides. That looks good for gcc and VS.
If you don't mind using someone else's implementation:

http://www.leda-tutorial.org/en/unofficial/ch06s01.html
http://www.algorithmic-solutions.com/leda/

I'm sure there are plenty of other options out there, if you don't like this one.
int64_t is (now) a standard C type. These constants are defined in stdint.h
Topic archived. No new replies allowed.