• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: External C function and duplicate symbol
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: External C function and duplicate symbol


  • Subject: Re: External C function and duplicate symbol
  • From: Patrick Mau <email@hidden>
  • Date: Fri, 3 Oct 2008 15:30:06 +0200

Hi Christian

If you really want a function to appear in multiple object files
you could declare them static, like in:

static void vec_zero2(int *vect)
{
	vec[0] = vec[1] = 0;
}

This is sometimes useful if you want to inline small functions
and not use preprocessor macros like this:

static inline char *code_long(char *dst, u_int32_t in)
{
	dst[0] = (in >> 24) & 0xff; // '&' for readability only
	dst[1] = (in >> 16) & 0xff;
	dst[2] = (in >>  8) & 0xff;
	dst[3] = (in >>  0) & 0xff; // '>>' for readability only

	return dst;
}

This works also mixing C and Obj-C:

static void callSomething(id myObject, int x, y)
{
[myObject withX:x andY:y];
[myObject setTitle:[NSString stringWithFormat:@"Position: %d,%d", x, y]];
}


Of course this will increase your code size if you are not considering
the size of your static functions. 'otool' or the assembler listing within
XCode is useful to look at the generated code.


Everything else should be declared 'extern' and implemented in one
source file only. That's only my opinion, of course.

Regards,
Patrick

On 03.10.2008, at 13:19, Christian Giordano wrote:

Hi guys, I've few functions that I'm keeping on an external .h file.
If the header is included in more than a class I get duplicate symbol
error. I tried using #ifndef which I use on my C++ classes but didn't
bring any luck. I had a look to the various headers in the framework
and I saw they use the following sintax:

#define VEC_ZERO_2(a)				\
{						\
  (a)[0] = (a)[1] = 0.0;			\
}

Isn't there a way to achieve the same but having parameters and returns typed?


Thanks, chr

_______________________________________________

Cocoa-dev mailing list (email@hidden)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


References: 
 >External C function and duplicate symbol (From: "Christian Giordano" <email@hidden>)

  • Prev by Date: Re: External C function and duplicate symbol
  • Next by Date: Re: Newbie: Strange problem with NSTableView, check boxes and Core Data
  • Previous by thread: Re: External C function and duplicate symbol
  • Next by thread: Re: Newbie: Strange problem with NSTableView, check boxes and Core Data
  • Index(es):
    • Date
    • Thread