Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!sdd.hp.com!think.com!mintaka!bloom-beacon!eru!hagbard!sunic!liuida!c90davby From: c90davby@odalix.ida.liu.se (David Byers) Newsgroups: comp.sys.mac.programmer Subject: Re: Huh? What's wrong here... (A Simple Think C question) Message-ID: <1991Apr14.104649.20585@ida.liu.se> Date: 14 Apr 91 10:46:49 GMT References: <1991Apr14.021934.8840@watdragon.waterloo.edu> Sender: news@ida.liu.se (News Subsystem) Organization: CIS Dept, Univ of Linkoping, Sweden Lines: 63 jpmah@dahlia.uwaterloo.ca (John Mah) writes: >Ok. Simple it is, but I still can't figure out what's wrong: >I have a function: >long _get_new_hash_val(some parameters) >etc, etc... >{ > long value; > ...some statements... > return value; >} >Now, I call it with: >*my_pointer_to_a_long = _get_new_hash_val(some parameters); >Ok, it compiles fine and everything, but (upon examination with the ThinkC >debugger) that when I hit the return function, value = 0x2CEDE78A. >Now after I execute the *my_pointer_to_a_long assignment, it has a value of >0xFFFFE78A. What is happening is that the assignment is cutting off the two >high bytes, but keeping the two low bytes. >My question is: "Why does it do that and how can I fix it?". Thanks in advance. >(PS. I'm using Think C 4.0.2 -- great package) My guess, and is is only a guess, since I have not seen all of your source code, is that when you call _get_new_hash_val() from a file other than the one it is defined in, the top two bytes are cut off. That is due to the fact that the ANSI specs say the an undeclared function is assumed to take any number of parameters, and redurns in int, and that an int is equivalent of a short int in THINK C, that is two bytes. To fix it you need to declare _get_new_hash_val() in the file/function you are using it. That can either be accomplished by creating a header file (like hashfuns.h, or whatever you wand), and place the line: long _get_new_hash_val([Your parameters go here]); in it. While you are at it, do the same for all other functions in the file. Then #include the header file in every finle that uses functions that are declared in the header. If you do not want to create a header file, you can put the line: extern long _get_new_hash_val(); in the declaration section of the file/function/block hat uses _get_new_hash_val(). C compilers (mercifully) does not complain if a function called is not declared, but the compiler willl make certain assumptions, leaving it to the linker to find the function. The linker, however, will scream its head off if a function is not defined. -- _____________________________________ ____________________________________ | David Byers ||SnailMail: David Byers | | || Ryds Alle 9:204 | | c90davby@odalix.ida.liu.se || S-58251 Linkoping | | byers@nanny.lysator.liu.se || SWEDEN | `-------------------------------------'`------------------------------------'