From: Gauthier Ostervall <gauthier@ostervall.se>
To: 14133@debbugs.gnu.org
Subject: bug#14133: 24.2; c functions recognition breaks on certain preprocessor macros
Date: Wed, 3 Apr 2013 12:48:37 +0200 [thread overview]
Message-ID: <CAM8gEgg-b2njsy_BE9orqdBsEaVvT4SPeWF=vtUcjD8pgz9CBQ@mail.gmail.com> (raw)
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?
next reply other threads:[~2013-04-03 10:48 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-04-03 10:48 Gauthier Ostervall [this message]
2013-04-09 6:33 ` bug#14133: 24.2; c functions recognition breaks on certain preprocessor macros 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
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to='CAM8gEgg-b2njsy_BE9orqdBsEaVvT4SPeWF=vtUcjD8pgz9CBQ@mail.gmail.com' \
--to=gauthier@ostervall.se \
--cc=14133@debbugs.gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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.