in reply to Re^4: Need Help with perlxstut
in thread Need Help with perlxstut
The Inline C docs tell you what types are supported natively (for conversion). You can handle any type you like but since you can define an infinite number......
You have several issues. First you don't seem to understand typing properly (based on assigning floats to integers in the C++ example above). You also don't seem to understand what header files are for. This is pretty basic stuff and makes it hard to know where to start.
So what's a header for. Well first you don't need one. All the code can be in the main.c All the code can be in the header.h for that matter. To really understand headers you need to understand types and functions and how compilers work. We declare types using typdef statements for our convenience. Rather than write unsigned long long we might use a typdef to alias that to uint64. The preprocessor effectively does a search and replace, replacing every instance of uint64 with 'unsigned long long' which is a type the compiler understands. The function declarations in the header help the compiler. Under the covers when you call a function this is what happens (simplified). The arguments to the function are pushed onto the stack. The compiler knows how much space it need because an int will take 4 bytes, a short 2 bytes, a char 1 byte, a pointer 4 bytes, etc. The memory address of the instruction following the function call is also pushed onto the stack (so we know where to return to). Last of all control of execution passed to the entry point (first instruction) of the function. The function will strip it arguments off the stack, do its stuff, push its return value onto the stack, and then return control of execution to the return location (the instruction following the function call). In order for the compiler to put together the necessary code it needs to know what arguments a function takes and what it returns. By declaring the functions as prototypes in the header file you avoid issues with code like:
int func1 ( int a ) { return func2( a ); } int func2 ( int b ) { return b*b; }
In this code the compiler gets to func1, sees the call to func2 but does not know how to handle it. By declaring the functions in the header you avoid compile errors like this. The header declaration must be exactly the same as the real function. All you need to do is cut and paste the function call up to the opening curly and add a ;
A header file lets you declare a function. At the compiler level that is essentially just an argument list, return type and and *entry point*. The entry point is where the actualy code that does the stuff lives. You can compile C without having this code present. For example take stdio.h You can find stdio.h but you won't find stdio.c So how does that work. The compiled binary code that actually does the stdio stuff is found in stdlibc (cc and gcc on *nix) or msvcrt (cl.exe on win32). When you compile your code you get an object file. To make it work it is linked to the C library code that actually implements the functions. Linking can be static in which case the relevant binary code from the library is actually stuck into your final executable of dynamic in which case it it not. With dynamic linking you depend on the fact that the stdlib functions will be found at runtime. These are the .lib and .dll files on Win32.
Anyway Inline will give you the .al error if it can't do the type conversion automatically. The header declaration 'unsigned varname' is shorthand for 'unsigned int varname' where the 'int' declaration is implicit. Inline may of may not cope with that. If as you said you only included the main.c code then there is an obvious problem. In this code there will be lots of bitmask_t types, but without the header the compiler has no idea what that is.
Handling the bitmask_t coord[] pointer and its conversion will be your main issue. There are several ways to do it, including the one I showed you before.
It is not that hard. I suggest getting just one function working to start. Rinse and repeat.
cheers
tachyon
|
|---|