LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 11-16-2011, 06:38 AM   #1
shamjs
Member
 
Registered: Sep 2011
Posts: 93

Rep: Reputation: Disabled
macro defination


Hi all,
im using macro in my project and im using g++ compiler to copile the code

here is my code

Code:
/*******olux.h*********/
#ifndef _OLUX_H
#define _OLUX_H

#if WIN32
#define MY_API(ret_type) ret_type __stdcall
#else
#define MY_API(ret_type) extern "C" __declspec(dllexport) ret_type 
#endif

MY_API(long) olpOpenPredictor(long *ohPredHandle);//line 168
#endif
Code:
/*******olupx.cpp*********/

MY_API(long) olpOpenPredictor( long *ohPredHandle)//this func is in global scope
{
.//here i have some code
.
}
whenever i compile this program i will get the error has
olupx/inc/olux.h:168: error: expected constructor, destructor, or type conversion before â(â token
please suggest me where i have went wrong
 
Old 11-16-2011, 06:50 AM   #2
millgates
Member
 
Registered: Feb 2009
Location: 192.168.x.x
Distribution: Slackware
Posts: 852

Rep: Reputation: 389Reputation: 389Reputation: 389Reputation: 389
what exactly is
Code:
#if WIN32
supposed to do?
didn't you mean

Code:
#ifdef _WIN32
or

Code:
#if defined(_WIN32)
 
Old 11-16-2011, 07:13 AM   #3
shamjs
Member
 
Registered: Sep 2011
Posts: 93

Original Poster
Rep: Reputation: Disabled
Since im compiling the same program in windows also hence im using
#if WIN32

ya i mean to say #ifdef _WIN32 or #if defined(_WIN32)
 
Old 11-16-2011, 07:21 AM   #4
NevemTeve
Senior Member
 
Registered: Oct 2011
Location: Budapest
Distribution: Debian/GNU/Linux, AIX
Posts: 4,862
Blog Entries: 1

Rep: Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869
Fixed version:

Code:
#if WIN32
#define MY_API(ret_type) ret_type __stdcall
#else
#define MY_API(ret_type) ret_type
#endif
Reasons:
1. extern "C" doesn't belong here, specify globally
2. __declspec(dllexport) means nothing for g++
 
Old 11-17-2011, 12:07 AM   #5
shamjs
Member
 
Registered: Sep 2011
Posts: 93

Original Poster
Rep: Reputation: Disabled
now i have declared extern "C" globally
here is my code
Code:
/*********olux.h*********/
#ifndef _OLUX_H
#define _OLUX_H

#if WIN32
#define MY_API(ret_type) ret_type __stdcall
#else
#define MY_API(ret_type) ret_type //line 100
#endif

#if defined(__GNUC__) || #if WIN32 //line 168
#ifdef  __cplusplus
extern "C"
{
#endif
MY_API(long) olpOpenPredictor(long *ohPredHandle);
#ifdef  __cplusplus
}
#endif
#endif
#endif
Code:
/*******olupx.cpp*********/

MY_API(long) olpOpenPredictor( long *ohPredHandle)//this func is in global scope
{
.//here i have some code
.
}
but now im getting the error has
olupx/inc/olux.h:168:33: error: missing binary operator before token "WIN32"

im using #ifdef WIN32 in line 168 (because i need that same code to be executed on windows)

and whether it is required to use __attribute__ in line 100(i.e #define MY_API(ret_type) __attribute__ ret_type)
please suggest me to do
waiting for your reply.............
 
Old 11-17-2011, 02:43 AM   #6
NevemTeve
Senior Member
 
Registered: Oct 2011
Location: Budapest
Distribution: Debian/GNU/Linux, AIX
Posts: 4,862
Blog Entries: 1

Rep: Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869
Code:
#ifndef _OLUX_H
#define _OLUX_H

#ifdef WIN32
#define MY_API(ret_type) ret_type __stdcall
#else
#define MY_API(ret_type) ret_type
#endif

#ifdef  __cplusplus
extern "C" {
#endif

MY_API(long) olpOpenPredictor(long *ohPredHandle);

#ifdef  __cplusplus
}
#endif

#endif
 
1 members found this post helpful.
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
defination of "task_struct". shiru Linux - Newbie 6 12-31-2010 05:14 AM
problem with a function defination aa.bb.cc Programming 3 07-16-2010 07:28 AM
sigmatel high defination audio not working on RHEL 4.0 sachin_malik Linux - Hardware 0 08-03-2007 11:50 AM
how to install Realtek high defination audio driver in redhat linux 9.0 graphic mode blpradeep Linux - Hardware 2 07-15-2006 04:26 PM
#defining a macro inside a macro? saravkrish Programming 1 05-24-2005 09:48 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 05:01 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration