Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.c > #23388

Re: Taking address of struct temporary

From Ike Naar <ike@sverige.freeshell.org>
Newsgroups comp.lang.c
Subject Re: Taking address of struct temporary
Date 2012-07-19 06:31 +0000
Organization A noiseless patient Spider
Message-ID <slrn3vfsk0faev.ke4.ike@sverige.freeshell.org> (permalink)
References <73b21861-a104-4d94-8d44-747adbfbb7b3@t1g2000pbl.googlegroups.com>

Show all headers | View raw


On 2012-07-19, nroberts <roberts.noah@gmail.com> wrote:
> I've been playing around with an object library and have run into an
> inconsistency between using it under a C compiler and using it under a
> C++ compiler.
>
> I wanted a way to declare "objects" statically, meaning they exist as
> constants.  I did something like the following:
>
> struct Object {
>   struct Class const* isa;
> };
>
> struct String_ {
>   struct Object const _;
>   char const* buf;
>   int len;
> };
>
> extern void* __X_STR;
>
> #define xstr(X) &(struct String_){ { __X_STR }, X, sizeof(X) };
>
> The '__X_STR' variable is defined statically in a C file.

Elsethread is has been explained why __X_STR is not a well chosen name.
What has not been mentioned yet is that name mangling can be a problem.
You say the __X_STR variable is defined in a C file. If you refer to
it as plain extern in a C++ file the names will probably not match, and
you'll have to use

  extern "C" void * __X_STR;

Back to comp.lang.c | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

Taking address of struct temporary nroberts <roberts.noah@gmail.com> - 2012-07-18 18:58 -0700
  Re: Taking address of struct temporary Keith Thompson <kst-u@mib.org> - 2012-07-18 19:27 -0700
    Re: Taking address of struct temporary nroberts <roberts.noah@gmail.com> - 2012-07-19 08:54 -0700
  Re: Taking address of struct temporary Eric Sosman <esosman@ieee-dot-org.invalid> - 2012-07-18 22:31 -0400
  Re: Taking address of struct temporary Ike Naar <ike@sverige.freeshell.org> - 2012-07-19 06:31 +0000
    Re: Taking address of struct temporary nroberts <roberts.noah@gmail.com> - 2012-07-19 08:57 -0700

csiph-web