| Author |
Include a <map> in a .c file
|
|
| viveque.kumar@gmail.com 2006-01-09, 11:10 pm |
| How do I go about including #include <map> in my .c file? It is giving
me a lot of errors the moment i include it...
Everything is fine until I add the <map> include... I suspect it to be
something with C style file and C++ style compilation,...?
My header, where I am trying to include is:
#ifndef _CARDCOMM_H_
#define _CARDCOMM_H_ 1
#include <stdio.h>
#include <string.h>
#if defined(WIN32) || defined(UNDER_CE)
#include <windows.h>
#include <winscard.h>
#else
#include <pcsclite.h>
#endif
#include <map>
Please help...
- Vivek
| |
| Stephen Howe 2006-01-09, 11:10 pm |
| > How do I go about including #include <map> in my .c file? It is giving
> me a lot of errors the moment i include it...
[snip]
You have not posted the error messages you are getting.
And the snippet that you posted is correct.
I suspect you have "forgotten" that the C++ library is in the std namespace.
You either want
using namespace std; // It is a bad style to place this statement in
a .h file
after your includes
or alternatively to prefix declarations with std::
so
std::map <int, int> m;
Stephen Howe
| |
| Ulrich Eckhardt 2006-01-09, 11:10 pm |
| viveque.kumar@gmail.com wrote:
> How do I go about including #include <map> in my .c file? It is giving
> me a lot of errors the moment i include it...
>
> Everything is fine until I add the <map> include... I suspect it to be
> something with C style file and C++ style compilation,...?
Right. <map> is a C++ header and you can't include it in a C program. You
might however be able to compile your whole C program as C++, in that
direction C++ is pretty downward compatible.
> #ifndef _CARDCOMM_H_
> #define _CARDCOMM_H_ 1
Wrong, you are not allowed to use symbols beginning with an underscore and a
capital. Also, how likely do you think it is that someone else used the
exact same include guard? Just add some random data and your include guard
suddenly becomes much less likely to collide with others.
> #if defined(WIN32) || defined(UNDER_CE)
I use this, it catches CE too, at least in all cases I know:
#if defined(WIN32) || defined(_WIN32)
cheers
Uli
| |
| viveque.kumar@gmail.com 2006-01-09, 11:10 pm |
| All my declarations are prefixed with std::
Okay I get errors like these:
C:\Program Files\Microsoft Visual Studio .NET
2003\Vc7\include\cstdio(17) : error C2143: syntax error : missing '{'
before ':'
C:\Program Files\Microsoft Visual Studio .NET
2003\Vc7\include\functional(14) : error C2143: syntax error : missing
'{' before '<'
C:\Program Files\Microsoft Visual Studio .NET
2003\Vc7\include\cstddef(17) : error C2143: syntax error : missing '{'
before ':'
These errors come the moment I do a #include<map>, no objects are
defined for map as yet.
Thanks,
Vivek
| |
| Mateusz Łoskot 2006-01-09, 11:10 pm |
| viveque.kumar@gmail.com wrote:
>
> These errors come the moment I do a #include<map>, no objects are
> defined for map as yet.
>
Read what Ulrish Eckhardt wrote:
"Right. <map> is a C++ header and you can't include it in a C program.
You might however be able to compile your whole C program as C++, in
that direction C++ is pretty downward compatible."
So, you can not include C++ headers to C application.
Your file has .c extension and VC++ preprocessor and compiler will treat
it as C source code but they fail in this case.
Cheers
--
Mateusz Łoskot
http://mateusz.loskot.net
| |
| Mateusz Łoskot 2006-01-09, 11:10 pm |
| Mateusz Łoskot wrote:
> viveque.kumar@gmail.com wrote:
>
>
> Read what Ulrish Eckhardt wrote:
>
Sorry for my typo in Ulrich's name above: not sh byt ch!
Cheers
--
Mateusz Łoskot
http://mateusz.loskot.net
| |
| viveque.kumar@gmail.com 2006-01-09, 11:10 pm |
| In that case how do I include the STL::Map into a c file?
| |
| Duane Hebert 2006-01-09, 11:10 pm |
|
"Ulrich Eckhardt" <eckhardt@satorlaser.com> wrote in message
news:6bjq73-o6l.ln1@satorlaser.homedns.org...
>
> Wrong, you are not allowed to use symbols beginning with an underscore and
> a
> capital. Also, how likely do you think it is that someone else used the
> exact same include guard? Just add some random data and your include guard
> suddenly becomes much less likely to collide with others.
Also, is there a typo in the #define line or does the
OP want to check if _CARDCOMM_H_ is defined
and if not, define _CARDCOMM_H_1 ? What
purpose would that serve?
| |
| Igor Tandetnik 2006-01-09, 11:10 pm |
| "Duane Hebert" <spoo@flarn2.com> wrote in message
news:ukWaUi2BGHA.3840@TK2MSFTNGP15.phx.gbl
> "Ulrich Eckhardt" <eckhardt@satorlaser.com> wrote in message
> news:6bjq73-o6l.ln1@satorlaser.homedns.org...
>
>
> Also, is there a typo in the #define line or does the
> OP want to check if _CARDCOMM_H_ is defined
> and if not, define _CARDCOMM_H_1 ? What
> purpose would that serve?
There is a space between a trailing underscore and the character 1. A
macro named _CARDCOMM_H_ is defined to expand to 1. Symbol _CARDCOMM_H_1
does not appear anywhere in the code fragment above.
--
With best wishes,
Igor Tandetnik
With sufficient thrust, pigs fly just fine. However, this is not
necessarily a good idea. It is hard to be sure where they are going to
land, and it could be dangerous sitting under them as they fly
overhead. -- RFC 1925
| |
| Duane Hebert 2006-01-09, 11:10 pm |
|
"Igor Tandetnik" <itandetnik@mvps.org> wrote in message
news:OhWuV42BGHA.1088@tk2msftngp13.phx.gbl...
> There is a space between a trailing underscore and the character 1. A
> macro named _CARDCOMM_H_ is defined to expand to 1. Symbol _CARDCOMM_H_1
> does not appear anywhere in the code fragment above.
Ah. Didn't see that with my font. But even so, what benefit does
this give over just defining it in this case?
| |
| Igor Tandetnik 2006-01-09, 11:10 pm |
| "Duane Hebert" <spoo@flarn.com> wrote in message
news:O6fG9C9BGHA.3920@tk2msftngp13.phx.gbl...
>
> "Igor Tandetnik" <itandetnik@mvps.org> wrote in message
> news:OhWuV42BGHA.1088@tk2msftngp13.phx.gbl...
>
>
> Ah. Didn't see that with my font. But even so, what benefit does
> this give over just defining it in this case?
Not much. But it's also harmless.
--
With best wishes,
Igor Tandetnik
With sufficient thrust, pigs fly just fine. However, this is not
necessarily a good idea. It is hard to be sure where they are going to
land, and it could be dangerous sitting under them as they fly
overhead. -- RFC 1925
|
|
|
|