0

python code

for b in range(4):
 for c in range(4):
 print myfunc(b/0x100000000, c*8)

c code

unsigned int b,c;
for(b=0;b<4;b++)
 for(c=0;c<4; c++)
 printf("%L\n", b/0x100000000);
 printf("%L\n" , myfunc(b/0x100000000, c*8)); 

I am getting an error saying: error: integer constant is too large for "long" type at both printf statement in c code. 'myfunc' function returns a long. This can be solved by defining 'b' a different type. I tried defining 'b' as 'long' and 'unsigned long' but no help. Any pointers?


My bad...This is short version of problem

unsigned int b;
b = 1;
printf("%L", b/0x100000000L);

I am getting error and warnings: error: integer constant is too large for "long" type warning: conversion lacks type at end of format warning: too many arguments for format

Bill the Lizard
407k213 gold badges579 silver badges892 bronze badges
asked Apr 17, 2011 at 17:34
3
  • 4
    You're missing some curly braces in your C code. Commented Apr 17, 2011 at 17:36
  • 1
    For long integer constants use 0x100000000L Commented Apr 17, 2011 at 17:37
  • 2
    What output are you expecting here? Any integer type divided by a larger value is just going to be zero. Commented Apr 17, 2011 at 18:29

3 Answers 3

3

Your C code needs braces to create the scope that Python does by indentation, so it should look like this:

unsigned int b,c;
for(b=0;b<4;b++)
{
 for(c=0;c<4; c++)
 {
 printf("%L\n", b/0x100000000);
 printf("%L\n" , myfunc(b/0x100000000, c*8)); 
 }
}
answered Apr 17, 2011 at 17:38
Sign up to request clarification or add additional context in comments.

Comments

1

Try long long. Python automatically uses number representation which fits your constants, but C does not. 0x100000000L simply does not fit in 32-bit unsigned int, unsigned long and so on. Also, read your C textbook on long long data type and working with it.

answered Apr 17, 2011 at 19:42

Comments

0
unsigned int b,c;
const unsigned long d = 0x100000000L; /* 33 bits may be too big for int */
for(b=0;b<4;b++) {
 for(c=0;c<4; c++) { /* use braces and indent consistently */
 printf("%ud\n", b/d); /* "ud" to print Unsigned int in Decimal */
 printf("%ld\n", myfunc(b/d, c*8)); /* "l" is another modifier for "d" */
 }
}
answered Apr 17, 2011 at 20:06

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.