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

Re: Cast operation or string conversion?

Victor Bazarov wrote:
A pair of size_t objects is *most likely* bigger than an unsigned int.
HI, Victor, I studied better my code and realised that I can use that
observe function only by passing the uint32 pointer to it (the *string
version does other things). So I guess now I have a more serious
problem, that of uniquely mapping this pair of (size_t size_t) to and
uint32. What do you propose to do?

Is it possible to cast

An idea is to go redefine the observe function using uint64_t instead of
uint32

observe(uint64_t* wordid);

and then convert each size_t into a uint32 and chain them into a uint64.
Does it sound reasonable?Something like this

uint64_t chain(uint32_t one, uint32_t two) {
// get two 32bit rands and concatenate
uint64_t longrand = one;
longrand <<= 32;
longrand |= two;
return longrand;
}

but I have no clue on how to get a uint32 out of a size_t and if it's
feasible.
Can you suggest other ways?

Thanks so much again

Giuseppe

You cannot dynamic_cast anything except pointers to polymorphic classes.
That means the approach you're describing is not going to work.

I would say convert your tuple into a string using hexadecimal or some
other notation and pass the pointer to that string to your 'observe'
function.

BTW, what's the reason you're passing pointers and not references?

V
Jul 12 '08 #1
1 3249
Giuseppe:G: wrote:
Victor Bazarov wrote:
>A pair of size_t objects is *most likely* bigger than an unsigned int.

HI, Victor, I studied better my code and realised that I can use that
observe function only by passing the uint32 pointer to it (the *string
version does other things). So I guess now I have a more serious
problem, that of uniquely mapping this pair of (size_t size_t) to and
uint32. What do you propose to do?
You need to take a close look at the meaning of those size_t values, why
they are paired, what is unique about them. Generally speaking, if they
can have any value and you have no limit of those pairs, then the number
of possible pairs is std::numeric_limits<size_t>::max()^2. If, on the
other hand, the number of combinations is generally limited, then you
could create a mapping by declaring a static map with all size_t pairs
you encounter and an ever-increasing index. Look the pair up, if it's
there, use the index you've assigned to it, if not there, assign a new
index, store the mapping, and 'observe' the new index.
>
Is it possible to cast

An idea is to go redefine the observe function using uint64_t instead of
uint32

observe(uint64_t* wordid);

and then convert each size_t into a uint32 and chain them into a uint64.
Does it sound reasonable?Something like this

uint64_t chain(uint32_t one, uint32_t two) {
// get two 32bit rands and concatenate
uint64_t longrand = one;
longrand <<= 32;
longrand |= two;
return longrand;
}

but I have no clue on how to get a uint32 out of a size_t and if it's
feasible.
Can you suggest other ways?

V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
Jul 14 '08 #2

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

Similar topics

8
by: Ganesan Rajaraman | last post by:
In the following examples, why the first case statement works and why the second doesn't, I wonder. Could anyone shed some light on this? Thanks, Ganesh -- this is an attempt to: -- ...
3
by: Harry Keck | last post by:
I would imagine that this is a pretty trivial operation, but I can not figure out how to cast a string variable to a Decimal. I tried Decimal dVariable = (Decimal)strStringVariable, but it does not...
9
by: rsine | last post by:
I have developed a program that sends a command through the serial port to our business system and then reads from the buffer looking for a number. Everything worked great on my WinXP system, but...
33
by: Samuel R. Neff | last post by:
We've been doing a little experimenting and it seems VB.NET doesn't have a direct equivalent to a C# double to integer cast. Dim d as Double = 2.5# Dim i as Integer = CType(d, Integer) Is...
0
by: John Jenkins | last post by:
Hi, can anyone shed some light on an issue I have encountered. I have used a tool (Cape Clear) to generate a WSDL file for me. When I use the WSDL2Java tool provided by apache axis it creates...
4
by: dba_222 | last post by:
Dear Experts, Ok, I hate to ask such a seemingly dumb question, but I've already spent far too much time on this. More that I would care to admit. In Sql server, how do I simply change a...
17
by: arindam.mukerjee | last post by:
I was running code like: #include <stdio.h> int main() { printf("%f\n", 9/5); return 0; }
5
by: aaragon | last post by:
Hi everyone, I wrote a very simple function to try to understand the casting of variables in C++. The function is function foo() { std::vector<inttest(100); randomize(test); unsigned long...
0
by: Giuseppe:G: | last post by:
Hi Ali, thanks very much. Below are some further questions. acehreli@gmail.com wrote: Well I guess it would because, observe basically just increments some global value and I don't think it...
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: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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
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
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
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

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.