lilypond-devel
[Top][All Lists]
Advanced

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

Re: lily/freetype-error.cc: const struct #include ;


From: Wols Lists
Subject: Re: lily/freetype-error.cc: const struct #include ;
Date: Mon, 06 Sep 2010 23:51:34 +0100
User-agent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.2.7) Gecko/20100727 Thunderbird/3.1.1

 On 06/09/10 22:30, Wols Lists wrote:
> As a C programmer, it took me about 30 seconds (or less) to twig what it
> was doing.
>> > I mean, why _do_ we have a hanging = sign?  I could understand if it
>> > was any of these:
>> > } ft_errors = 0;
>> > } ft_errors = NULL;
>> > } ft_errors;
>> >
>> > (with the #include being higher up in the file), but it seems really
>> > weird to have a dangling = sign in there.
>> >
> Because C doesn't give a monkeys about white space, but the
> pre-processor does. The #include has to be the first thing on the line
> otherwise the pre-processor will screw up, but once the pre-processor
> has done its job, the compiler will happily ignore all the surplus new
> lines.
Following up on myself (and assuming you've read Werner's post), here
follows a short lesson in C by someone who's forgotten all the detail,
but can remember the gist ...

The fragment of code you're looking at both declares and initialises an
array. Excuse me if I've got my syntax wrong, but it goes something like
this ...

const struct Freetype_error_message // this bit is the structure definition
{
  FT_Error     err_code;
  const char*  err_msg;
// this bit now declares the array and fills it
} ft_errors[] = ( (1, "message1"), (2, "message2"), (0, 0) ) ;


That bit between the "=" and ";" initialises the array (and I've almost 
certainly got my syntax complete crap :-). It's convenient to store that in a 
separate file (fterrors.h). And because #include has to be at the START of a 
line (and C doesn't give a monkeys about that), you end up with the code 
looking like the example you're moaning at.

As I said, it might not be *good* code, it might not be *pretty*, but it *is* 
sane :-)

Cheers,
Wol






reply via email to

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