inline problem

Started by
6 comments, last by lshadow 24 years, 3 months ago
For some reason I keep getting a linking error anytime I try to inline one of my functions. Here is the error it is giving me. LNK2001: unresolved external symbol "int __cdecl DrawPixel(int,int,unsigned short,unsigned short *,int)" (?DrawPixel@@YAHHHGPAGH@Z) The function looks like this: typedef unsigned short WORD inline int DrawPixel(int x, int y, WORD color, WORD *dest, int lpitch) { dest[x+y*(lpitch>>1)] = color; return 1; } Thanks for any help, well time to get back to programming.
Working on: DoP
Advertisement
Is the inline definition in the same source file? And is it defined before it is called? The link error seems to indicate that the compiler thinks DrawPixel is a external function without definition (i.e. You are calling DrawPixel before the source definition of it).
The inline function is in a different source file, but I''m pretty sure that it is defined before it is called. If I remove the inline definition then the function works fine...that''s what confuses me the most.
The inline function is in a different source file, but I''m pretty sure that it is defined before it is called. If I remove the inline definition then the function works fine...that''s what confuses me the most.
Working on: DoP
The inline code cannot be in a source module (.cpp)
It needs to be in the header file (.h) where the function is declared.

This lets the compiler see the definition for the function and that you are trying to inline it.

When the inline succeeds that code will be more or less pasted into where it goes in the place it is used. Otherwise a function call is compiled into that module for linking purposes ( and maybe stripped out later if there are redundant versions )

Hope this helps

Edited by - SteveC on 2/2/00 4:40:30 PM
Ahhh thanks SteveC, this problems has been bugging me aswell
Well, Im proto typin an inline func in a header file, then declaring it in a module, and my works fine, weird
Esap1: That only works if something inside the function forces it outline (normal). Things like for() loops do that. Try commenting out all of the code except the return statement (if there is one), and see if that changes anything.

Also, it's pretty much up to the compiler to decide whether to ignore your request to inline or not.

That would be a simple way to check if it's really being inlined though...

- null_pointer


Edited by - null_pointer on 2/3/00 7:24:40 AM

This topic is closed to new replies.

Advertisement