UnSigned Long

J

Joriveek

Hi,

I want to store myvarz = 3000000000;

I have declared myvarz as unsigned long; still not taking.


I am using MSVC++ 6.0

Any help please urgent....

Thanks
J.
 
J

Johan Borkhuis

Joriveek said:
Hi,

I want to store myvarz = 3000000000;

I have declared myvarz as unsigned long; still not taking.

Please provide some more information (for example a small example
program showing your problem together with the output of this program).
I am using MSVC++ 6.0

Some people are lucky, others are not.....

Kind regards,
Johan

--
o o o o o o o . . . _____J_o_h_a_n___B_o_r_k_h_u_i_s___
o _____ || http://www.borkhuis.com |
.][__n_n_|DD[ ====_____ | (e-mail address removed) |
>(________|__|_[_________]_|________________________________|
_/oo OOOOO oo` ooo ooo 'o!o!o o!o!o`
== VxWorks FAQ: http://www.xs4all.nl/~borkhuis/vxworks/vxworks.html ==
 
M

manoj1978

Joriveek said:
Hi,

I want to store myvarz = 3000000000;

I have declared myvarz as unsigned long; still not taking.

#include <stdio.h>

int main(void)
{
unsigned int myvarz = 3000000000;
printf("%u\n",myvarz);
return 0;
}
This is working in msvc++ 6.0 and gcc.Please post your code

Johan said:
Some people are lucky, others are not.....
very true.
 
M

Mike Wahler

Joriveek said:
Hi,

I want to store myvarz = 3000000000;

I have declared myvarz as unsigned long; still not taking.

unsigned long myvarz = 3000000000
I am using MSVC++ 6.0

Any help please urgent....

The C language standard requires that type 'unsigned long'
can represent a minimum range of values from zero (0) through
4294967295, inclusive. Your value 3000000000 falls within
this range.


I compiled the following code with Microsoft
Visual C++ v6.0 :

#include <stdio.h>

int main()
{
unsigned long myvarz = 0;
myvarz = 3000000000;
printf("%lu\n", myvarz);
return 0;
}

I got output of:

3000000000


So perhaps you could specify what you mean by 'not taking'.
How did you verify there's a problem? With a debugger?
Did you print out the value? If so, which 'printf()' format
specifier did you use?


-Mike
 
A

Alexei A. Frounze

Joriveek said:
Hi,

I want to store myvarz = 3000000000;

I have declared myvarz as unsigned long; still not taking.

I am using MSVC++ 6.0

I don't know what's not taking what, but long is at least 32-bit long, hence
unsigned long will fit your 3000000000 nicely.

But you'll have problems multiplying this number in integer arithmetics
(using longs only) by anything other than 1. If that's what you have, you
should probably use long long (or _int64 as per msvc++, which doesn't know
long long) or go for double or long double, which has more bits in mantissa
than simple long (up to 80 if I'm not mistaken are supported by x86/x87
FPU).
Any help please urgent....

Alive yet? :)
Alex
 
E

Emmanuel Delahaye

Joriveek wrote on 29/08/05 :
I want to store myvarz = 3000000000;

I have declared myvarz as unsigned long; still not taking.

I am using MSVC++ 6.0

Check your ULONG_MAX (in <limits.h>) It could be not big enough for the
value you want.

In that case, you have several solutions:

Use a smaller value.
Use a larger type:
- [C99] long long or unsigned long long
- some extension of your IDE with '64' in its name...
Use a lower precision type (like a double).
Kill the dog.

--
Emmanuel
The C-FAQ: http://www.eskimo.com/~scs/C-faq/faq.html
The C-library: http://www.dinkumware.com/refxc.html

"There are 10 types of people in the world today;
those that understand binary, and those that dont."
 
M

Mike Wahler

Emmanuel Delahaye said:
Joriveek wrote on 29/08/05 :

Check your ULONG_MAX (in <limits.h>) It could be not big enough for the
value you want.

It is large enough. I suspect OP didn't tell us the
whole story.

-Mike
 
P

Peter Nilsson

#include <stdio.h>

int main(void)
{
unsigned int myvarz = 3000000000;
printf("%u\n",myvarz);
return 0;
}
This is working in msvc++ 6.0 and gcc.

It should 'work' on any implementation, but may print values
like 24064 since unsigned int is not required to have more than
16 value bits.
 
K

Keith Thompson

Mike Wahler said:
It is large enough. I suspect OP didn't tell us the
whole story.

He certainly didn't. The above is all the information the OP gave us,
except for the "Any help please urgent...." at the end of the article.
There's no reason to think he can't store the value 3000000000 in an
unsigned long, and no clue what he means by "still not taking".

If it's really urgent, presumably he'll be following this thread and
will jump in any moment with a clearer explanation of what he's asking
for. Until then, there's really no point in speculating.

I'm tempted to suggest that if somebody posts an unclear question, and
somebody else has posted a followup asking for clarification, we
should drop the thread. Unfortunately there doesn't seem to be any
good way to drop a thread.

To any newbies reading this:

If you're having a problem, please give us the information we need to
help you solve it. I understand that it's hard to know just what
information is needed, so sometimes we'll need to go back and forth a
couple of times. Some hints:

Provide a small complete (compilable and executable) program that
exhibits the problem. The "compilable and executable" part is
optional if the problem is that it won't compile or execute.

Don't use any system-specific headers. If you need them to
illustrate the problem, you need to post to a system-specific
newsgroup. If you don't know which headers are system-specific,
we'll be glad to offer advice. (We're sometimes a bit
over-sensitive about topicality, so be patient.)

Tell us what you expect the code to do and what it actually does.
If you get error messages, show them to us. Cut-and-paste both
the code and the error messages; don't try to summarize or re-type
them.

If your problem description is equivalent to "It doesn't work",
you're not giving us enough information.

These are not arbitrary rules; they're ways you can help us to help
you. Any extra time they cost you will be more than paid back in the
speed with which we can either give you an answer to tell you where to
find the people who can.
 
M

Mike Wahler

Peter Nilsson said:
It should 'work' on any implementation, but may print values
like 24064 since unsigned int is not required to have more than
16 value bits.

Note that the OP indicated he's using type 'unsigned long',
not 'unsigned int'. 'unsigned long' must contain at least
32 bits.

-Mike
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top