On Apr 21, 11:16am,
plug@arcticmail.com wrote:
> So, what was your preferred indentation style back then?
> Do you still prefer your old style but you're being
> "encouraged" to use a style you don't like, or have
> you switched styles? And of course, "why?" :)
Run GNU indent over some C code with "indent -kr -psl -nce -l80" and
that's pretty much my preferred indentation style. The style that I
*must* use when working on GDB is pretty much what you get when
running GNU indent over the same C code with no options (i.e, just the
defaults).
E.g, here's an example of some code indented using "-kr -psl -nce -l80":
void
ia64_extract_return_value(struct type *type, char *regbuf, char *valbuf)
{
struct type *float_elt_type;
float_elt_type = is_float_or_hfa_type(type);
if (float_elt_type != NULL) {
int offset = 0;
int regnum = IA64_FR8_REGNUM;
int n = TYPE_LENGTH(type) / TYPE_LENGTH(float_elt_type);
while (n-- > 0) {
ia64_register_convert_to_virtual(regnum, float_elt_type,
®buf[REGISTER_BYTE(regnum)],
valbuf + offset);
offset += TYPE_LENGTH(float_elt_type);
regnum++;
}
}
else
memcpy(valbuf, ®buf[REGISTER_BYTE(IA64_GR8_REGNUM)],
TYPE_LENGTH(type));
}
And here's the same code indented according to the recommendations in
the GNU coding standard, i.e, "indent" with no options:
void
ia64_extract_return_value (struct type *type, char *regbuf, char *valbuf)
{
struct type *float_elt_type;
float_elt_type = is_float_or_hfa_type (type);
if (float_elt_type != NULL)
{
int offset = 0;
int regnum = IA64_FR8_REGNUM;
int n = TYPE_LENGTH (type) / TYPE_LENGTH (float_elt_type);
while (n-- > 0)
{
ia64_register_convert_to_virtual (regnum, float_elt_type,
®buf[REGISTER_BYTE (regnum)],
valbuf + offset);
offset += TYPE_LENGTH (float_elt_type);
regnum++;
}
}
else
memcpy (valbuf, ®buf[REGISTER_BYTE (IA64_GR8_REGNUM)],
TYPE_LENGTH (type));
}
I don't really mind this style too much anymore. It did take
me some time to get used to it though. The two mistakes that
I still occassionally make are:
- forgetting to put in a space between the function name
and left paren.
- putting the left curly brace on its own line indented by
two spaces.
As for the "Why?" question, the GDB project has decided to follow
the recommended indentation style described in the GNU coding
standard:
http://www.gnu.org/prep/standards_22.html#SEC22
As mentioned in my previous email, I think it's important for all
files in a particular project to use the same indentation style since
it makes it much easier to work different parts of the project without
needing to constantly make minor adjustments. I've worked on projects
where the indentation scheme changes within a single file (usually
from function to function) and it's always distracting to try to
figure out how some new bit of code that you're adding ought to be
indented.
Kevin