UnSigned Long

Discussion in 'C Programming' started by Joriveek, Aug 29, 2005.

  1. Joriveek

    Joriveek Guest

    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.
     
    Joriveek, Aug 29, 2005
    #1
    1. Advertising

  2. 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[ ====_____ | |
    >(________|__|_[_________]_|________________________________|

    _/oo OOOOO oo` ooo ooo 'o!o!o o!o!o`
    == VxWorks FAQ: http://www.xs4all.nl/~borkhuis/vxworks/vxworks.html ==
     
    Johan Borkhuis, Aug 29, 2005
    #2
    1. Advertising

  3. Joriveek

    Guest

    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.
     
    , Aug 29, 2005
    #3
  4. Joriveek

    Mike Wahler Guest

    "Joriveek" <> wrote in message
    news:deunjb$ef8$...
    > 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
     
    Mike Wahler, Aug 29, 2005
    #4
  5. "Joriveek" <> wrote in message
    news:deunjb$ef8$...
    > 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
     
    Alexei A. Frounze, Aug 29, 2005
    #5
  6. 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."
     
    Emmanuel Delahaye, Aug 29, 2005
    #6
  7. Joriveek

    Mike Wahler Guest

    "Emmanuel Delahaye" <> wrote in message
    news:...
    > 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
     
    Mike Wahler, Aug 29, 2005
    #7
  8. 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
     
    Peter Nilsson, Aug 29, 2005
    #8
  9. "Mike Wahler" <> writes:
    > "Emmanuel Delahaye" <> wrote in message
    > news:...
    >> 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) <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.
     
    Keith Thompson, Aug 30, 2005
    #9
  10. Joriveek

    Mike Wahler Guest

    "Peter Nilsson" <> wrote in message
    news:...
    > 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
     
    Mike Wahler, Aug 30, 2005
    #10
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. George Marsaglia

    Assigning unsigned long to unsigned long long

    George Marsaglia, Jul 8, 2003, in forum: C Programming
    Replies:
    1
    Views:
    693
    Eric Sosman
    Jul 8, 2003
  2. Replies:
    1
    Views:
    457
    Diez B. Roggisch
    Jun 1, 2005
  3. sridhar

    comparing unsigned long and unsigned int

    sridhar, Nov 1, 2004, in forum: C Programming
    Replies:
    6
    Views:
    453
    J. J. Farrell
    Nov 3, 2004
  4. Daniel Rudy

    unsigned long long int to long double

    Daniel Rudy, Sep 19, 2005, in forum: C Programming
    Replies:
    5
    Views:
    1,205
    Peter Shaggy Haywood
    Sep 20, 2005
  5. pozz
    Replies:
    12
    Views:
    750
    Tim Rentsch
    Mar 20, 2011
Loading...

Share This Page