473,396 Members | 1,918 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,396 software developers and data experts.

Arbitrary Type Definition

Suppose I wanted to go about defining a three or four bit unsigned integer
type. How would I go about doing that? Thanks
Jul 19 '05 #1
4 3913
"Now With More Salt" <co**************@yahoo.com> wrote
Suppose I wanted to go about defining a three or four bit unsigned integer
type. How would I go about doing that? Thanks


You're going to have to provide a bit more motivation and explanation.
C++ doesn't have a 16 bit integral type, a 32 bit integral type or an 8 bit
integral type and gets along fine without them. What are you trying to do?

Regards,
Buster.
Jul 19 '05 #2
"Now With More Salt" <co**************@yahoo.com> wrote in message
news:bk**********@news-int.gatech.edu...
Suppose I wanted to go about defining a three or four bit
unsigned integer type. How would I go about doing that?


You could use a bit field embedded in a struct, but it would
not be treated as an equal with the builtins and would not
be packed optimally. C++ doesn't really let you specify the
size of types in that amount of detail. The resolution for type
sizes is sizeof(char). However, if you specify the operations
you want to support, and the expectations you have for the
type, you might be able to cobble together something that is
suitable for your purposes.

Dave
Jul 19 '05 #3

Now With More Salt <co**************@yahoo.com> wrote in message
news:bk**********@news-int.gatech.edu...
Suppose I wanted to go about defining a three or four bit unsigned integer
type. How would I go about doing that?


I'd create a class that wraps a std::bitset<num_of_bits>
and define whatever operations I need (e.g. arithmetic,
comparison with other types, etc.)

-Mike

Jul 19 '05 #4
Now With More Salt wrote:
Suppose I wanted to go about defining a three or four bit unsigned integer
type. How would I go about doing that? Thanks


One method is to use an existing integral type that is bigger
than what you need, and perhaps typedef it.

For example, if your platform's native integral type uses
64 bits, then you would only use the "lower" 3 or 4 bits.

But if your processor has a native integral type that
uses 3 or 4 bits, then I suggest assembly language.

--
Thomas Matthews

C++ newsgroup welcome message:
http://www.slack.net/~shiva/welcome.txt
C++ Faq: http://www.parashift.com/c++-faq-lite
C Faq: http://www.eskimo.com/~scs/c-faq/top.html
alt.comp.lang.learn.c-c++ faq:
http://www.raos.demon.uk/acllc-c++/faq.html
Other sites:
http://www.josuttis.com -- C++ STL Library book

Jul 19 '05 #5

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

Similar topics

4
by: Ced | last post by:
Hi, i'm not an expert in C but i try to compile BTNG software under linux kernel 2.4.2-2. I get these errors at the very first stage. Does someone could have a rapid look on this and tell me...
3
by: Bret Pehrson | last post by:
I'm working on a (non-trivial) project which includes various & numerous objects, some in my direct source control, some not. I'm finding the need to somehow associate one object with another,...
12
by: Chadwick Boggs | last post by:
I need to perform modulo operations on extremely large numbers. The % operator is giving me number out of range errors and the mod(x, y) function simply seems to return the wrong results. Also,...
5
by: Steven D'Aprano | last post by:
I have a problem and I don't know where to start looking for a solution. I have a class that needs to call an arbitrary function and wait for a result. The function, being completely arbitrary...
669
by: Xah Lee | last post by:
in March, i posted a essay “What is Expressiveness in a Computer Language”, archived at: http://xahlee.org/perl-python/what_is_expresiveness.html I was informed then that there is a academic...
2
by: darknails | last post by:
Hi, I would like to know how to define a arbitrary mathematical function with one variable and a list of paramter, like, f(x). For example, in GSL library this is done as /* Definition of an...
2
by: waylonflinn | last post by:
I'm looking for a way to invoke methods with an arbitrary number of parameters of arbitrary type from within a single method, when those parameters are known at the time of invocation of the...
28
by: walterbyrd | last post by:
Python seems to have a log of ways to do collections of arbitrary objects: lists, tuples, dictionaries. But what if I want a collection of non-arbitrary objects? A list of records, or something...
4
by: Steven Simpson | last post by:
Stefan Ram wrote (in "More than one language in a page"): Is this a new trend of user-agent writers (Microformats, and now Google) staking claims on the @class namespace? I'm surely not the only...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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
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
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development projectplanning, coding, testing,...

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.