flat assembler
Message board for the users of flat assembler.

Index > High Level Languages > Fasm with C

Author
Thread Post new topic Reply to topic
masterducky



Joined: 12 May 2010
Posts: 10
masterducky
I found the example for mixing Fasm with C code but there isnt example in it
for what i want to do.

I wanna declare this in Fasm to get its value in C.
Code:
 MyVar  dd 0     


So i go like this in Fasm:
Code:
public MyVar:dword as '_MyVar' 
    

but it wont compile.

In C I'd like it to be an int:

Code:
extern int MyVar;    
Post 12 May 2010, 14:08
View user's profile Send private message Reply with quote
LocoDelAssembly
Your code has a bug


Joined: 06 May 2005
Posts: 4633
Location: Argentina
LocoDelAssembly
If you use "public MyVar as '_MyVar' " instead it will compile and AFAIK it will link with your C object despite the type-less nature of the symbol.
Post 12 May 2010, 14:31
View user's profile Send private message Reply with quote
masterducky



Joined: 12 May 2010
Posts: 10
masterducky
Thanks for the answer LocoDelAssembly!

No it wont compile that way either.

But i found out what i missed in the example code and now it compiles like this:

Code:
public MyVar as '_MyVar'
MyVar dd 0      


But i cant seem to access it in C.

I get "error LNK2019: unresolved external symbol "int MyVar"" error.

Is there any relation of the size that i declared it as DD in fasm and INT in C?

Can it be the problem?
Post 12 May 2010, 15:30
View user's profile Send private message Reply with quote
LocoDelAssembly
Your code has a bug


Joined: 06 May 2005
Posts: 4633
Location: Argentina
LocoDelAssembly
Have you tried without the underscore and adding one more?
Post 12 May 2010, 16:11
View user's profile Send private message Reply with quote
masterducky



Joined: 12 May 2010
Posts: 10
masterducky
No, but i found it:

Code:
extern "C" int MyVar;    


This is it. Now i have access. Smile

One more question though:

Do i still need to invoke ExitProcess in the fasm code when i link it with C ?
Post 12 May 2010, 16:50
View user's profile Send private message Reply with quote
pelaillo
Missing in inaction


Joined: 19 Jun 2003
Posts: 878
Location: Colombia
pelaillo
Quote:

Do i still need to invoke ExitProcess in the fasm code when i link it with C ?

If you have the "C" main() procedure as the entry point, your compiler will include all the exit routines to properly terminate the program. Check it in a dump of the linked executable.
Post 12 May 2010, 19:22
View user's profile Send private message Yahoo Messenger Reply with quote
bitshifter



Joined: 04 Dec 2007
Posts: 764
Location: Massachusetts, USA
bitshifter
It sounds like you are really using C++ (not C)
So for it to work under either language you could do this...
Code:
#ifdef __cplusplus
extern "C" {
#endif

/* TODO: put stuff here... */

#ifdef __cplusplus
}
#endif
    

_________________
Coding a 3D game engine with fasm is like trying to eat an elephant,
you just have to keep focused and take it one 'byte' at a time.
Post 13 May 2010, 00:13
View user's profile Send private message Reply with quote
masterducky



Joined: 12 May 2010
Posts: 10
masterducky
Thanks a lot Pelaillo and Bitshifter!
Post 13 May 2010, 07:06
View user's profile Send private message Reply with quote
Tyler



Joined: 19 Nov 2009
Posts: 1216
Location: NC, USA
Tyler
You might be interested in http://en.wikipedia.org/wiki/Name_mangling#How_different_compilers_mangle_the_same_functions, it explains the reason you need to use "extern 'C'" on that page also. Name mangling is really unstandardized for C++.
Post 05 Jun 2010, 22:12
View user's profile Send private message Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2020, Tomasz Grysztar. Also on GitHub, YouTube, Twitter.

Website powered by rwasa.