By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,730 Members | 1,500 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,730 IT Pros & Developers. It's quick & easy.

UnSigned Long

P: n/a
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.
Nov 15 '05 #1
Share this Question
Share on Google+
9 Replies


P: n/a
Joriveek wrote:
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[ ====_____ | jo***@borkhuis.com |(________|__|_[_________]_|________________________________|

_/oo OOOOO oo` ooo ooo 'o!o!o o!o!o`
== VxWorks FAQ: http://www.xs4all.nl/~borkhuis/vxworks/vxworks.html ==
Nov 15 '05 #2

P: n/a
Joriveek wrote:
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 Borkhuis wrote: Some people are lucky, others are not.....

very true.

Nov 15 '05 #3

P: n/a

"Joriveek" <no****@please.com> wrote in message
news:de**********@reader01.news.esat.net...
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
Nov 15 '05 #4

P: n/a
"Joriveek" <no****@please.com> wrote in message
news:de**********@reader01.news.esat.net...
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
Nov 15 '05 #5

P: n/a
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."
Nov 15 '05 #6

P: n/a

"Emmanuel Delahaye" <em***@YOURBRAnoos.fr> wrote in message
news:mn***********************@YOURBRAnoos.fr...
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.


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

-Mike
Nov 15 '05 #7

P: n/a
ma*******@gmail.com wrote:
Joriveek wrote:
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.


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.

--
Peter

Nov 15 '05 #8

P: n/a
"Mike Wahler" <mk******@mkwahler.net> writes:
"Emmanuel Delahaye" <em***@YOURBRAnoos.fr> wrote in message
news:mn***********************@YOURBRAnoos.fr...
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.


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.

--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
Nov 15 '05 #9

P: n/a

"Peter Nilsson" <ai***@acay.com.au> wrote in message
news:11**********************@g14g2000cwa.googlegr oups.com...
ma*******@gmail.com wrote:
Joriveek wrote:
> 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.


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

Nov 15 '05 #10

This discussion thread is closed

Replies have been disabled for this discussion.