What's wrong with this macro?

  • Thread starter Michael B Allen
  • Start date
M

Michael B Allen

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)
 
M

Michael B Allen

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
 

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