473,785 Members | 2,129 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

about extern "C"

I want use a c lib in vc6. so I use extern "C" to c function, include
three files "test.cpp", "b.h" and "b.c":

//*************** *************** *************** ***
// test.cpp
#include "stdafx.h"
#include "b.h"
int main(int argc, char* argv[])
{

return b();
}

//*************** *************** *************** ***
//b.h
#if !defined __B_HHHHHH
#define __B_HHHHHH

#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000

extern "C" int b(); //error occur

#endif

//*************** *************** *************** ***
//b.c
#include "b.h"
int b()
{
return 111;
}

error:
d:\test\testco\ b.h(10) : error C2059: syntax error : 'string'

I think it's simple, but what wrong? owing to my ide?
Jul 23 '05 #1
2 3486
flyaflya wrote:
I want use a c lib in vc6. so I use extern "C" to c function, include
three files "test.cpp", "b.h" and "b.c":

//*************** *************** *************** ***
// test.cpp
#include "stdafx.h"
#include "b.h"
int main(int argc, char* argv[])
{

return b();
}

//*************** *************** *************** ***
//b.h
#if !defined __B_HHHHHH
This is not a valid identifier. You must not define identifiers that contain
two consecutive underscores, because those are reserved for the compiler
and the standard library.
#define __B_HHHHHH

#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000

extern "C" int b(); //error occur

#endif

//*************** *************** *************** ***
//b.c
#include "b.h"
int b()
{
return 111;
}

error:
d:\test\testco\ b.h(10) : error C2059: syntax error : 'string'

I think it's simple, but what wrong? owing to my ide?


extern "C" is not valid in C code, only in C++ code. Try something like:

#ifdef __cplusplus
extern "C"
#endif
int b();

Jul 23 '05 #2
"flyaflya" <fl******@gmail .com> дÈëÏûÏ¢ÐÂÎÅ:d5 **********@news .yaako.com...
I want use a c lib in vc6. so I use extern "C" to c function, include
three files "test.cpp", "b.h" and "b.c":

//*************** *************** *************** ***
// test.cpp
#include "stdafx.h"
#include "b.h"
int main(int argc, char* argv[])
{

return b();
}

//*************** *************** *************** ***
//b.h
#if !defined __B_HHHHHH
#define __B_HHHHHH

#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000

extern "C" int b(); //error occur

#endif

//*************** *************** *************** ***
//b.c
#include "b.h"
int b()
{
return 111;
}

error:
d:\test\testco\ b.h(10) : error C2059: syntax error : 'string'

I think it's simple, but what wrong? owing to my ide?


i have finded the answer, the file "b.c" can't include "b.h", because
extern "C" just can be compiled in cpp file, can't be parsered in c file.
language C is not same as language CPP usually include head file.
Jul 23 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
4258
by: Sergei | last post by:
I ran into this problem. I needed to create an entry for access to a library of functions that are "extern C", and I just can't find the right syntax, if it exists at all ( I am using MSVC 6.0-7.1).. Note, that basically I don't need an "extern C" linkage, I just need to define a type to cast a resolved function address.. Any ideas? Basically , I need something like this..
1
2651
by: terrencel | last post by:
I was told to look at some old C code that was ported to C++. One of the file is like: ========================================= CPPClass* someCPPVar = NULL; extern "C" {
111
6473
by: JKop | last post by:
Okay here we go, I feel it's about time people conversed about the bullshit aspects of C++ (including the bullshit stuff brought forward from C). I'll begin with a few of my own grievances: 1) The whole "function declaration Vs object definition" fiasco, which results in the following (temporary creating) syntax: Blah poo = Blah();
8
2183
by: Generic Usenet Account | last post by:
Our C++ program was linked with some legacy C functions. We had used the extern "C" declaration, and everything was working fine. Then someone thought that it would be better to have a consistent file naming convention and renamed the files with the legacy C functions from .c to .cxx. Lo and behold we started getting linker errors left and right. When we reverted back to the old naming convention, the problem went away. Also, the...
12
2730
by: G Patel | last post by:
I've seen some code with extern modifiers in front of variables declared inside blocks. Are these purely definitions (no definition) or are they definitions with static duration but external linkage? Not much on this in the FAQ or tutorials.
19
3860
by: ccwork | last post by:
Hi all, I am reading "C: A Reference Manual" 4th ed and I get lost for the "extern". It says that global object without specifying the storage-class specifier will have "extern" as the default storage-class specifier. My (little) C experience tells me that an object with "extern" is to let the linker knows that the object is referencing the object defined in somewhere, and this "somewhere" object does not have the storage-class specifier...
4
4759
by: kk_oop | last post by:
Hi. I need to write a C++ callback function and register it with a C program. I've read that this can be done if the callback function is a static method. I've also read that I should use a global function with the extern "C" prefix. I was leaning toward using the static method approach until I saw a posting that said compatibility between static C++ functions and C is not guaranteed in the respective language standards. This made me...
4
6260
by: mimi | last post by:
The programmer indicates to the compiler that a function is written in a different programming language using a linkage directives.It is intuitive that extern "SomeLanguage" is used to declare functions written in the "SomeLanguage". But I am quite confused what information does the linkage directive tells the compiler.The "generated" function name? The way the arguments are ordered?Or something else? And I am still wondering why extern...
1
2845
by: manchin2 | last post by:
Hi, Can anybody please provide the information about "&quot" and its use, if possible please provide an example. 1)<tm:bom-expression>{Conf.getEquityConfLookupFields().getEventFieldText(&quot;AdditionalDisruption&quot;,&quot;Change in Law&quot;)}</tm:bom-expression> 2)07:41:08 Default ( call ( . ( call ( . Conf getEquityConfLookupFields ) ) getEventFieldText ) ( , AdditionalDisruption Change inLaw ) ) value=Not applicable Can you please...
0
9646
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10157
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10097
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8983
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7505
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6742
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5518
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4055
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2887
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.