[HH] c++ strings?

Greg London email at greglondon.com
Tue Nov 27 15:30:37 EST 2012


I've finally gotten a few cycles to work on this again,
and I am getting a weird error message:

::import "DPI" function void Note( string const &msg);
::                                              |
::ncvlog: *E,CNSTRF (topmodule.v,2|46): The keyword 'const' must
::        be followed by 'ref' in formal argument lists.

The import "DPI" thing is how I'm supposed to tell my verilog
simulator what the C functions will look like.

This might be a problem with the verilog simulator (which is being a bear
to work with) but I just wanted to check if anyone recognized
the "'const' must be followed by 'ref'" message and saw something
stupid that I was missing?

Thanks,
Greg



> Are you sure about that Jerry?  I've never seen the ampersand after the
> variable name...
>
> Look at the examples here:
>   http://www.parashift.com/c++-faq/overview-refs.html
>
>
> On 11/20/2012 04:17 PM, Jerry Feldman wrote:
>> No, after msg. That means call by reference in C++
>>
>> On 11/20/2012 03:33 PM, Greg London wrote:
>>> Should I put the "&" in front of msg? i.e.
>>>
>>> void _say(const string &msg){
>>>
>>>
>>>> Almost perfect. I would make a few minor changes.
>>>>
>>>> void _say(const string msg&){
>>>> 	cout<<msg;
>>>> }
>>>>
>>>>
>>>> void Note(const string msg&){
>>>> 	_say("Note: "+msg);
>>>> }
>>>>
>>>> Minor efficiencies. In your code in when note() is called the string
>>>> is
>>>> copied so msg is a copy of the input. In _say("Note: "+msg);
>>>>   you are creating a new string, but that string is also copied.
>>>> Setting up
>>>> a call by reference saves 2 copies in this case. The compiler can
>>>> optimize the _say function to where the call by reference does not
>>>> matter, but not the note() function which is external.
>>>>
>>>>
>>>> --
>>>> Jerry Feldman <gaf at blu.org>
>>>> Boston Linux and Unix
>>>> PGP key id:3BC1EB90
>>>> PGP Key fingerprint: 49E2 C52A FC5A A31F 8D66  C0AF 7CEA 30FC 3BC1
>>>> EB90
>>>>
>>>>
>>>> _______________________________________________
>>>> Hardwarehacking mailing list
>>>> Hardwarehacking at blu.org
>>>> http://lists.blu.org/mailman/listinfo/hardwarehacking
>>>>
>>>
>>
>>
>>
>>
>> _______________________________________________
>> Hardwarehacking mailing list
>> Hardwarehacking at blu.org
>> http://lists.blu.org/mailman/listinfo/hardwarehacking
>>
>
> _______________________________________________
> Hardwarehacking mailing list
> Hardwarehacking at blu.org
> http://lists.blu.org/mailman/listinfo/hardwarehacking
>


-- 





More information about the Hardwarehacking mailing list