all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* bug#14133: 24.2; c functions recognition breaks on certain preprocessor macros
@ 2013-04-03 10:48 Gauthier Ostervall
  2013-04-09  6:33 ` Gauthier Östervall
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: Gauthier Ostervall @ 2013-04-03 10:48 UTC (permalink / raw)
  To: 14133

Function coloring, c-beginning-of-defun and c-end-of-defun behaves
strangely if the functions contain ifdef'd code.

For example:
void function_one(void)
{
    // Make the number of spaces before # vary.
    #if defined(DEBUG)
    trap();
    #endif // DEBUG
}


void function_two(void)
{
    // doing nothing
}


The number of spaces that precede the macros seem to influence the
strange behavior.

At first I thought that the c-*-of-defun functions worked if both
C-macros were aligned, but it is not always the case.

It is quite easy to see if the current state is working or not: the
identifier 'function_two' is not colored correctly when the function
recognition fails.

There seems also to be differences depending on the form of the macro:
#if defined(DEBUG)
#if defined DEBUG
#ifdef DEBUG

The cases showing the fault depend on the previous states, the file
content alone is not enough to guarantee seeing the fault.

Examples of code that causes the fault (only function_one is shown for
readability, see above for function_two):

--- 1 ---
1.a.
// -- OK
void function_one(void)
{
    // Make the number of spaces before # vary.
#if defined DEBUG
    trap();
#endif // DEBUG
}

1.b. Add one space before #if -> Fail
1.c. Add one more space before #if -> OK
1.d. Delete the space added in 1.c. -> still OK (although same content
as in 1.b.).


--- 2 ---
2.a.
// --- OK
void function_one(void)
{
    // Make the number of spaces before # vary.
#if defined DEBUG
    trap();
#endif // DEBUG
}

2.b. Add one space before #if -> OK (unlike case 1)
2.c. Add one more space before #if -> Fail
2.d. Delete the space added in 2.c. -> still Fail (although same
content as in 2.b.).
2.e. Remove the last space before #if -> OK


--- 3 ---
3.a.
// --- OK
void function_one(void)
{
    // Make the number of spaces before # vary.
#if defined DEBUG
    trap();
#endif // DEBUG
}

3.b. Add four spaces before #if -> Fail
3.c. Add one space before #endif -> Fail
3.d. Add one space before #endif -> OK
3.e. Delete one space before #endif -> OK (although same content as 3.c)


As far as I can see, the behavior of #ifdef is the same as that of #if
defined without parens. The behavior of #if defined with parens
differs, though.

IIRC, all preprocessor macros should be considered as blank lines when
it comes to function recognition?



^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2013-04-15 16:19 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-04-03 10:48 bug#14133: 24.2; c functions recognition breaks on certain preprocessor macros Gauthier Ostervall
2013-04-09  6:33 ` Gauthier Östervall
2013-04-09 21:06 ` Alan Mackenzie
     [not found] ` <20130409210621.GA3571@acm.acm>
2013-04-10 11:49   ` Gauthier Östervall
2013-04-15 16:19 ` Alan Mackenzie

Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.