Jump to content
Sign in to follow this  
thiemann

Boostc Linker: Inline Usage Causes Link Error

Recommended Posts

Bug description:

The linker produces an error if the following code is compiled and linked.

 

Steps to reproduce:

1.) Create a new project

2.) Add a main.c file to the project with the following code

inline void serialSendChar(char value);

void DoThis()
{	
serialSendChar('a');
}

void serialSendChar(char value)
{
}

void interrupt()
{
}

void main()
{
}

 

3.) Compile and link the project using BoostC

4.) Notice the var not found error.

 

Expected behavior:

There should be no linker error.

 

Is the problem 100% reproducible:

Yes

 

SourceBoost version: 5.7

Compiler: BoostC

Compiler version: 1.7 Alpha

 

OS: Windows XP

 

Comments:

None

Share this post


Link to post
Share on other sites

Nice spot. An inline function must be declared with a body. Now fixed. Compiler will report an error for inline function declaration without a body.

 

Regards,

Pavel

Share this post


Link to post
Share on other sites

Even with the new 1.7.2 BoostC compiler, the linker generates an error if an inline function definition is located in another c module, but used in another c module.

 

Example:

Make a new project with two files (main.c and test.c)

In main.c, put the following code:

 

void dothis();

void interrupt()
{
    dothis();
}

void main()
{
    dothis();
}

 

In test.c, put the following code:

inline void dothis()
{

}

 

Compile and link the project.

Notice that the linker says that dothis() is an unresolved external symbol.

 

FYI: In main.c, I tried using "inline void dothis();" as the function prototype as well, but the compiler says that an inline function must be declared with a body.

Share this post


Link to post
Share on other sites
Even with the new 1.7.2 BoostC compiler, the linker generates an error if an inline function definition is located in another c module, but used in another c module.

 

Example:

Make a new project with two files (main.c and test.c)

In main.c, put the following code:

 

void dothis();

void interrupt()
{
    dothis();
}

void main()
{
    dothis();
}

 

In test.c, put the following code:

inline void dothis()
{

}

 

Compile and link the project.

Notice that the linker says that dothis() is an unresolved external symbol.

 

FYI: In main.c, I tried using "inline void dothis();" as the function prototype as well, but the compiler says that an inline function must be declared with a body.

 

 

I don't see any problem here. The code is incorrect and an error message is what should happen. At the point where an inline function is uses it should be declared/defined already. A good place for inline functions is a header hile.

 

Regards,

Pavel

Share this post


Link to post
Share on other sites

Pavel,

 

The dothis() is declared before it is used. It is declared as void dothis() in main.c before it is used in the main() function. Its definition is, however, located in another module, test.c, but this should not be a problem as this is a common thing to do.

 

I am not sure what is incorrect about the code. Please let me know what aspect you may be talking about so that I can clear that up.

 

Thanks,

 

Eric

Share this post


Link to post
Share on other sites
Pavel,

 

The dothis() is declared before it is used.  It is declared as void dothis() in main.c before it is used in the main() function.  Its definition is, however, located in another module, test.c, but this should not be a problem as this is a common thing to do.

 

I am not sure what is incorrect about the code.  Please let me know what aspect you may be talking about so that I can clear that up.

 

Thanks,

 

Eric

 

When an inline function is called compiler puts the body of this function into the place where call was made from. If this inline function doesn't have a body yet compiler has no code to place there. This is a fundamental difference between regular and inline functions. A regular function can have its definition and declaration in different modules but an inline function can't.

 

Regards,

Pavel

Share this post


Link to post
Share on other sites

Join the conversation

You are posting as a guest. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
Sign in to follow this  

×
×
  • Create New...