What's wrong with this macro?

Discussion in 'C Programming' started by Michael B Allen, Sep 1, 2004.

  1. Is there anything wrong with this macro?

    #define randint(a,b) (a)+(((b)-(a)+1)*(float)rand()/RAND_MAX)

    If I do randint(10, 0x10000) in a loop it sporatically generates:

    Program received signal SIGSEGV, Segmentation fault.
    0x00000000 in ?? ()

    with no backtrace and I compiled with debugging symbols. Could this be
    a bug in gcc?

    $ gcc -v
    Reading specs from /usr/lib/gcc-lib/i386-redhat-linux/2.96/specs
    gcc version 2.96 20000731 (Red Hat Linux 7.3 2.96-110)
     
    Michael B Allen, Sep 1, 2004
    #1
    1. Advertising

  2. On Wed, 01 Sep 2004 03:00:23 -0400, Michael B Allen wrote:

    > Is there anything wrong with this macro?
    >
    > #define randint(a,b) (a)+(((b)-(a)+1)*(float)rand()/RAND_MAX)
    >
    > If I do randint(10, 0x10000) in a loop it sporatically generates:
    >
    > Program received signal SIGSEGV, Segmentation fault. 0x00000000 in ?? ()


    Never mind. The bug is mine. Of course.

    Mike
     
    Michael B Allen, Sep 1, 2004
    #2
    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. Dead RAM
    Replies:
    20
    Views:
    1,132
    John Harrison
    Jul 14, 2004
  2. D Senthil Kumar

    macro name from macro?

    D Senthil Kumar, Sep 20, 2003, in forum: C Programming
    Replies:
    1
    Views:
    590
    Jack Klein
    Sep 21, 2003
  3. sounak

    to get macro name from macro value

    sounak, Nov 22, 2005, in forum: C Programming
    Replies:
    17
    Views:
    512
    Mark McIntyre
    Nov 22, 2005
  4. Patrick Kowalzick
    Replies:
    5
    Views:
    485
    Patrick Kowalzick
    Mar 14, 2006
  5. Mike Manilone

    macro inside macro

    Mike Manilone, Oct 3, 2011, in forum: C Programming
    Replies:
    8
    Views:
    474
    Mike Manilone
    Oct 6, 2011
Loading...

Share This Page