hi,
I am writing a c program in VC++ 6.
I have 2 files with 3 functions.
file-1 having two functions "a" and "c"
file-2 having a single function "b"
with function "a" as main() , "a" calls function "b" in file-2 which,
in turn calling function "c" in file-1.
function "c" and "b" are declared to return __int64. function "c"
returns it correctly but when it is assigned, it becomes a __int32 bit
number ( assigned to a __int64 var).
and interestingly, when i copy and paste the function "c" from file-2
to file 1, the program behaves as expected.
the code as is given below.
when "c" returns value to "b" it becomes __int32 format.
9007199237963776 becomes -16777216
file-1:
#include<stdio.h>
__int64 a();
__int64 b();
void main()
{
__int64 x;
x = b();
}
__int64 c()
{
__int64 y;
y = 9007199237963776;
return y;
}
file-2:
__int64 b()
{
__int64 z;
z = c();
return z;
} 8 3346
Hi,
Function "c" has no prototype in file-2.
Thus, the compiler (VC in this case) will asume "int".
Sugestion. Add "__int64 b(void);" at start of file-2.
Kind regards.
hurry wrote: hi,
I am writing a c program in VC++ 6.
[...] when "c" returns value to "b" it becomes __int32 format. 9007199237963776 becomes -16777216
[...] __int64 c() { __int64 y; y = 9007199237963776; return y; }
[...]
__int64, and __int32 might be windows/VC specific data types and not std
C. So I am assuming all it is trying to represent is integer types of 64
bit and 32 bit long.
From what's provided in the post, the problem might be in the
statement: y = 9007199237963776;
The answer lies in sizeof(int) on your system(and compiler, of course.)
9007199237963776 is an integer constant of type 'int'.
1FFFFFFF000000 which is more than 32 bits and so this might be getting
truncated even before getting assigned to y.
You can try doing, instead,
y = 9007199237963776L; or
y = 9007199237963776LL;
--
(Welcome) http://www.ungerhu.com/jxh/clc.welcome.txt
(clc FAQ) http://c-faq.com
Anand wrote: hurry wrote:
hi,
I am writing a c program in VC++ 6.
[...]
when "c" returns value to "b" it becomes __int32 format. 9007199237963776 becomes -16777216
[...]
__int64 c() { __int64 y; y = 9007199237963776; return y; }
[...] __int64, and __int32 might be windows/VC specific data types and not std C. So I am assuming all it is trying to represent is integer types of 64 bit and 32 bit long.
From what's provided in the post, the problem might be in the statement: y = 9007199237963776; The answer lies in sizeof(int) on your system(and compiler, of course.)
9007199237963776 is an integer constant of type 'int'. 1FFFFFFF000000 which is more than 32 bits and so this might be getting truncated even before getting assigned to y.
You can try doing, instead, y = 9007199237963776L; or y = 9007199237963776LL;
And, of course as tmp123 has rightly pointed out, the function c's
missing prototype might also be a strong (and main) candidate for the
problem.
--
(Welcome) http://www.ungerhu.com/jxh/clc.welcome.txt
(clc FAQ) http://c-faq.com
Anand wrote: Anand wrote: hurry wrote:
hi,
I am writing a c program in VC++ 6.
[...]
when "c" returns value to "b" it becomes __int32 format. 9007199237963776 becomes -16777216
[...]
__int64 c() { __int64 y; y = 9007199237963776; return y; }
[...] __int64, and __int32 might be windows/VC specific data types and not std C. So I am assuming all it is trying to represent is integer types of 64 bit and 32 bit long.
From what's provided in the post, the problem might be in the statement: y = 9007199237963776; The answer lies in sizeof(int) on your system(and compiler, of course.)
9007199237963776 is an integer constant of type 'int'. 1FFFFFFF000000 which is more than 32 bits and so this might be getting truncated even before getting assigned to y.
I think you need to learn a bit more about C since you are wrong. From
the latest standard:
| The type of an integer constant is the first of the corresponding list
| in which its value can be represented.
| Suffix DecimalConstant Constant
| none int int
| long int unsigned int
| long long int long int
| unsigned long int
| long long int
| unsigned long long int
....
| If an integer constant cannot be represented by any type in its list,
| it may have an extended integer type, if the extended integer type can
| represent its value. If all of the types in the list for the constant
| are signed, the extended integer type shall be signed. If all of the
| types in the list for the constant are unsigned, the extended integer
| type shall be unsigned. If the list contains both signed and unsigned
| types, the extended integer type may be signed or unsigned.
So basically it will an int if it fits, otherwise it will be the
smallest type in which it fits.
You can try doing, instead, y = 9007199237963776L; or y = 9007199237963776LL; And, of course as tmp123 has rightly pointed out, the function c's missing prototype might also be a strong (and main) candidate for the problem.
That will definitely be the problem, since without at least a
declaration in scope the compiler is required to assume the function
returns an int which of course can produce very strange results if that
is not true.
2 morals to this:
1) Don't give advice when you don't know the answer
2) Always use headers to provide the correct prototypes for functions.
--
Flash Gordon
Living in interesting times.
Although my email address says spam, it is real and I read it.
On 2005-12-28, Anand <An***@no-replies.com> wrote: y = 9007199237963776L; or
Not likely to fix it if long is 32 bits [AIUI likely on windows]
y = 9007199237963776LL;
Not likely if the compiler doesn't support "long long"
besides - IIRC integer literals have to be of a type large enough to
contain them if such a type exists.
hurry wrote: hi,
I am writing a c program in VC++ 6.
I have 2 files with 3 functions.
file-1 having two functions "a" and "c" file-2 having a single function "b"
[...]
when "c" returns value to "b" it becomes __int32 format. 9007199237963776 becomes -16777216
if you compiled the program, you might have noticed an error saying
"c undefined assuming extern returning int"
now read 6.8.6.4 bullet number 3 of C99 draft.
this explains alot, doesn't it?
haroon wrote:
[...] if you compiled the program, you might have noticed an error saying
pardon me, it's a warning not an error.
P.S. hurry, you if u put some thing like `extern __int64 c();'
on top of file-2 (where you defined c) it seems to work fine.
"hurry" <hu*********@gmail.com> writes: hi,
I am writing a c program in VC++ 6.
I have 2 files with 3 functions.
file-1 having two functions "a" and "c" file-2 having a single function "b"
with function "a" as main() , "a" calls function "b" in file-2 which, in turn calling function "c" in file-1.
function "c" and "b" are declared to return __int64. function "c" returns it correctly but when it is assigned, it becomes a __int32 bit number ( assigned to a __int64 var). and interestingly, when i copy and paste the function "c" from file-2 to file 1, the program behaves as expected.
the code as is given below.
when "c" returns value to "b" it becomes __int32 format. 9007199237963776 becomes -16777216
file-1:
#include<stdio.h> __int64 a(); __int64 b();
No such types in C.
typedef long long int64;
/* or if you really insist :
typedef __some_implementation_specific_type int64;
*/
void main()
int main(void)
The return type of main must be int! And the argument list
should be either (void), or (int, char**).
{ __int64 x; x = b(); }
Ever heard of indentation?
{
int64 x;
x = b(); /* or int64 x = b(); */
return 0; /* or EXIT_SUCCESS (from <stdlib.h> */
}
__int64 c() { __int64 y; y = 9007199237963776; return y; }
More indentation, and a little bit of simplification:
int64 c()
{
return 9007199237963776;
}
file-2:
Function below calls c() without prototype in scope.
int64 c();
In the current standard a diagnostic is required. In the previous standard
return type of int is assumed, but I'd be surprised if you don't get a
warning if you use proper flags to the compiler (if I remember correctly it
is /W4 on microsoft's compilers).
__int64 b() { __int64 z; z = c(); return z; }
int64 b()
{
return c();
}
/Niklas Norrthon This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: JR |
last post by:
Take a look at TestStruct1 and TestStruct2. Clearly, the D2 part of
the union is MUCH larger than the D1 portion. I would expect
sizeof(TestStruct1)==sizeof(TestStruct2) but that is not the case...
|
by: Skybuck Flying |
last post by:
Hi,
This is a somewhat cleaned up version 0.02 of the nrand48() routine.
There are still a few issues:
This code needs brackets but where ?
X = (uint64) xsubi << 32 | (uint32) xsubi << 16...
|
by: [GHO} |
last post by:
I trying to send an array to my C# dll function which the
prototype as "C# COM (Dll)":
public int PrintIO(out System.Int64 FreeIO ,out int len)
But when trying to call this function (CPP...
|
by: Jesse Hose |
last post by:
I get odd behavior in the debugger with the following code. The output of
the program itself is correct, but when I add the g_bad_int64_max and
g_bad_int64_min to the watch window they show values...
|
by: Kio |
last post by:
Hi,
For example:
1 __int64 fib4(__int64 n)
2 {
3 if ((n==1) || (n==2)) return 1;
4 else return (fib(n-1)+fib(n-2));
5 }
|
by: I.M. !Knuth |
last post by:
Hi. I'm more-or-less a C newbie. I thought I had pointers under control until
I started goofing around with this:
...
|
by: Angus |
last post by:
I need to convert a double to a 64 bit integer. I am using __int64
but could of course use a more portable type.
To perform the correct casts:
double d = 3.3;
__int64 i64;
i64 =...
|
by: Sri Harsha Dandibhotla |
last post by:
Hello all.
I recently came across a function declaration as :
char(*(*x()))();
This was not in some code but it was in a C questions thread on some
group.
I tried to decipher what it returns but...
|
by: Kenzogio |
last post by:
Hi,
I have a struct "allmsg" and him member :
unsigned char card_number; //16
allmsg.card_number
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome former...
|
by: taylorcarr |
last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: aa123db |
last post by:
Variable and constants
Use var or let for variables and const fror constants.
Var foo ='bar';
Let foo ='bar';const baz ='bar';
Functions
function $name$ ($parameters$) {
}
...
|
by: ryjfgjl |
last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
| |