• 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: Odd gcc error passing reference parameter to function
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Odd gcc error passing reference parameter to function


  • Subject: Re: Odd gcc error passing reference parameter to function
  • From: John Weeks <email@hidden>
  • Date: Fri, 11 Mar 2005 09:41:13 -0800

Jerry <email@hidden> said:

>> I have just started using Xcode. My first project is developing a
>> plug-in
>> for my company's main product. I thought that would be a good way to
>> introduce myself to Xcode.
>>
>> I have encountered a compile error that seems to me to be bogus and I
>> was
>> wondering if anyone can shed light on it. I define a function with this
>> prototype:
>>
>> int ExtractAnalogChannelInfo(string::iterator &currentC,
>> string::iterator
>> &theEnd, const string &termchars, long &channelNum, long &ctype, double
>> &Vmin, double &Vmax, int &termchar);
>>
>> This results in the error:
>>
>> error: in passing argument 2 of `int
>> ScanParse::ExtractAnalogChannelInfo(__gnu_cxx::__normal_iterator<char*,
>> std::basic_string<char, std::char_traits<char>, std::allocator<char> >
>> >&,
>> __gnu_cxx::__normal_iterator<char*, std::basic_string<char,
>> std::char_traits<char>, std::allocator<char> > >&, const std::string&,
>> long
>> int&, long int&, double&, double&, int&)'
>>
>> If I change the second parameter to pass-by-value instead of a
>> reference,
>> it compiles.
>>
>> VC++.net compiles the unchanged statement OK, and the first reference
>> compilesin Xcode, so it's not some obscure characteristic of
>> string::iterator (or is it?).
>>
>> Xcode: 1.5 IDE: 389.0 Core: 387.0 ToolSupport: 372.0
>> Running on OS X 10.3.7
>>
>> How do I found out the version of gcc on my machine?
>>
>> Thanks for any help with this.
>
>Are you passing in an expression as the parameter? VC++.net lets you
>take the reference of a temporary but GCC and CW don't.

Doink. Amazing how this stuff can make you feel dumb. Indeed, the
parameters are string::iterators with a call like this:

currentC = paramString.begin();
ExtractAnalogChannelInfo(currentC, paramString.end(), ...

currentC is assigned to a variable because it gets modified inside the
function. The second uses paramString.end() just to show the function where
to stop (of course). I had it as a reference to avoid copying.

1) I have read warnings about this numerous times. I should know better!

2) The second parameter should be at least const string::iterator &

3) I guess it is usual to pass such an iterator by value, at least that's
what STL always does. I take it that iterators are lightweight objects.

Thanks Jerry!

Regards,
John Weeks

WaveMetrics, Inc.
Phone (503) 620-3001
Fax   (503) 620-6754
email   email@hidden

 _______________________________________________
Do not post admin requests to the list. They will be ignored.
Xcode-users mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden

  • Prev by Date: Re: Exception reading pipe from NSTask using debugger
  • Next by Date: Uncaught exception trying to create a project
  • Previous by thread: Re: Odd gcc error passing reference parameter to function
  • Next by thread: Exception reading pipe from NSTask using debugger
  • Index(es):
    • Date
    • Thread