lilypond-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Allows inheritence for slur engravers (issue 7437048)


From: dak
Subject: Re: Allows inheritence for slur engravers (issue 7437048)
Date: Fri, 01 Mar 2013 17:51:36 +0000

On 2013/03/01 17:00:28, mike7 wrote:
On 1 mars 2013, at 17:30, mailto:address@hidden wrote:

> On 2013/03/01 14:45:27, mike7 wrote:
>
>> > "doubleSlurs" is not generic but rather specific.  I'd use
something
>> > like
>> > if (double_property_name_ && to_boolean (get_property
>> > (double_property_name_)))
>> > instead, then we can, if desired, have a separate
doublePhrasingSlur
>> > property at some point of time.
>
>> Done.  Had to make the check slightly different:
>
>>  if ((double_property_name_ != "")
>>       && to_boolean (get_property (double_property_name_.c_str
())))
>
> Oh, I'd have made double_property_name_ a const char * const instead
> of a string.  That can be 0, and you don't need to c_str on it.
>
>> as GCC complains that there is no operator && for the check you're
> suggesting.

I've always avoided using const char * because I never understood how
it works
with memory management.

Given that we are creating a pointer (an array of chars),

Uh, a pointer.  _Not_ an array of chars.  The array is "xxx".  We don't
create that array, it is statically allocated by the compiler and
remains the same over the life time of the program.  We just set the
pointer to point there.

wouldn't we have to
delete it in the destructor?  Furthermore, how does GCC know to
allocate the
correct amount of memory for the string?  Wouldn't that change
depending on the
length of the string?

That's probably the sort of thing you learn in a Freshman CS class...

That's C knowledge glossed over in C++.  If you write "whatever", this
allocates a static array in constant memory with the respective
characters (null-terminated) in them and returns a pointer to that
static array.  C is free to assume that you will not overwrite that
memory, so "xxx" and "xxx", written in two different source locations,
may or may not use the same memory location.

const char * does not work at all with memory management: it just takes
that pointer and uses it.  If it is from "xxx", you better never call
free or delete on that.

https://codereview.appspot.com/7437048/



reply via email to

[Prev in Thread] Current Thread [Next in Thread]