Can anyone recommend a program for indentation of C preprocessor
directives. My file looks like this:
#ifdef a
#define b
#else
#define c
#endif
int main()
{
return 0;
}
and I want a program able to automatically indent the preprocessor
directives.
I have already tried astyle, but with no success.
Bogdan 21 7644
Bogdan wrote:
Can anyone recommend a program for indentation of C preprocessor
directives. My file looks like this:
#ifdef a
#define b
#else
#define c
#endif
int main()
{
return 0;
}
and I want a program able to automatically indent the preprocessor
directives.
I have already tried astyle, but with no success.
indent(1) and vim both say that the source you provided is already
indented in a good way...
If what you want is something similar to this
#ifdef a
#define b
#else
#define c
#endif
, then I think you've got quite an unusual habit...
Bogdan
--
Pietro Cerutti
PGP Public Key: http://gahr.ch/pgp
On 21 May 2007, Pietro Cerutti <ga**@gahr.chwr ote:
Bogdan wrote:
>Can anyone recommend a program for indentation of C preprocessor directives. My file looks like this: #ifdef a #define b #else #define c #endif
int main() { return 0; } and I want a program able to automatically indent the preprocessor directives.
I have already tried astyle, but with no success.
indent(1) and vim both say that the source you provided is already
indented in a good way...
If what you want is something similar to this
#ifdef a
#define b
#else
#define c
#endif
, then I think you've got quite an unusual habit...
Maybe unusual, but at least *I* don't feel so lonely anymore ;-)
I think some compilers long ago didn't support preprocessor
directives with the # other than in the first column, but none I've
used in that past few years have that restriction. Seriously, isn't
the indented clause version *way* easier to read? If we indent if
clauses, why shouldn't we indent #if clauses for the same reason?
BTW, I don't use a separate program for this. My editor handles most
of it for me with it's autoindent feature.
Dave
--
D.a.v.i.d T.i.k.t.i.n
t.i.k.t.i.n [at] a.d.v.a.n.c.e.d .r.e.l.a.y [dot] c.o.m
David Tiktin wrote:
>
On 21 May 2007, Pietro Cerutti <ga**@gahr.chwr ote:
Bogdan wrote:
Can anyone recommend a program for indentation of C preprocessor
directives. My file looks like this:
#ifdef a
#define b
#else
#define c
#endif
[...]
and I want a program able to automatically indent the preprocessor
directives.
[...]
If what you want is something similar to this
#ifdef a
#define b
#else
#define c
#endif
, then I think you've got quite an unusual habit...
Maybe unusual, but at least *I* don't feel so lonely anymore ;-)
I think some compilers long ago didn't support preprocessor
directives with the # other than in the first column, but none I've
used in that past few years have that restriction.
I've seen programs keep the '#' in the first column, and insert
whitespace between it and the directive. (Does the Standard say
that this is allowed?) Using the same example:
#ifdef a
# define b
#else
# define c
#endif
Seriously, isn't the indented clause version *way* easier to read?
If we indent if clauses, why shouldn't we indent #if clauses for the
same reason?
When you have complex nested #if/#ifdef's, it is certainly easier
to read for me. However, I've been programming long enough that I've
used compilers that required the '#' in column 1, and no whitespace
following it, so I got in the habit of not indenting such things.
If the Standard guarantees both/either of the above, I just may
retrain myself.
[...]
--
+-------------------------+--------------------+-----------------------+
| Kenneth J. Brody | www.hvcomputer.com | #include |
| kenbrody/at\spamcop.net | www.fptech.com | <std_disclaimer .h|
+-------------------------+--------------------+-----------------------+
Don't e-mail me at: <mailto:Th***** ********@gmail. com>
Kenneth Brody wrote On 05/21/07 16:56,:
David Tiktin wrote:
>>On 21 May 2007, Pietro Cerutti <ga**@gahr.chwr ote:
>>>Bogdan wrote:
Can anyone recommend a program for indentation of C preprocessor directive s. My file looks like this: #ifdef a #define b #else #define c #endif
[...]
>>>>and I want a program able to automatically indent the preprocessor directive s.
[...]
>>>If what you want is something similar to this
#ifdef a #define b #else #define c #endif
, then I think you've got quite an unusual habit...
Maybe unusual, but at least *I* don't feel so lonely anymore ;-)
I think some compilers long ago didn't support preprocessor directives with the # other than in the first column, but none I've used in that past few years have that restriction.
I've seen programs keep the '#' in the first column, and insert
whitespace between it and the directive. (Does the Standard say
that this is allowed?) Using the same example:
#ifdef a
# define b
#else
# define c
#endif
>>Seriously, isn't the indented clause version *way* easier to read? If we indent if clauses, why shouldn't we indent #if clauses for the same reason?
When you have complex nested #if/#ifdef's, it is certainly easier
to read for me. However, I've been programming long enough that I've
used compilers that required the '#' in column 1, and no whitespace
following it, so I got in the habit of not indenting such things.
If the Standard guarantees both/either of the above, I just may
retrain myself.
White space is allowed both before and after the #.
What's more, it can be any species of white space:
/*#ifdef A*/#/*include <stdio.h>*/else/*include "stdio.h"*/
As with most of C, good sense is not enforced.
-- Er*********@sun .com
On 21 May, 22:37, Eric Sosman <Eric.Sos...@su n.comwrote:
White space is allowed both before and after the #.
What's more, it can be any species of white space:
/*#ifdef A*/#/*include <stdio.h>*/else/*include "stdio.h"*/
As with most of C, good sense is not enforced.
Really?
gcc gives me "`#else' not within a conditional" for that line, with or
without the "-ansi -pedantic" flags. ke***@bytebroth ers.co.uk wrote:
On 21 May, 22:37, Eric Sosman <Eric.Sos...@su n.comwrote:
> White space is allowed both before and after the #. What's more, it can be any species of white space:
/*#ifdef A*/#/*include <stdio.h>*/else/*include "stdio.h"*/
As with most of C, good sense is not enforced.
Really?
Really.
gcc gives me "`#else' not within a conditional" for that line, with or
without the "-ansi -pedantic" flags.
That's nice. But that only reinforces Eric's point: the line
above is a #else, but written in a diabolical fashion devoid
of good sense.
[To be fair, most programming languages allow similar exhibitions
of sense without sensibility, since they're blind to the meaning
of names & natural language.]
--
The shortcuts are all full of people using them.
Hewlett-Packard Limited registered office: Cain Road, Bracknell,
registered no: 690597 England Berks RG12 1HN
Bogdan wrote:
Can anyone recommend a program for indentation of C preprocessor
directives. My file looks like this:
#ifdef a
#define b
#else
#define c
#endif
int main()
{
return 0;
}
and I want a program able to automatically indent the preprocessor
directives.
I have already tried astyle, but with no success.
$ indent -kr -ppi 3 -st your_file.c
#ifdef a
# define b
#else
# define c
#endif
int main()
{
return 0;
}
--
Tor <torust [at] online [dot] no>
Tor Rustad wrote:
$ indent -kr -ppi 3 -st your_file.c
Which version of indent are you using?
Mine, on FreeBSD-6.2-STABLE doesn't have any of the options you're using...
Thanks
--
Pietro Cerutti
PGP Public Key: http://gahr.ch/pgp
Pietro Cerutti wrote:
Tor Rustad wrote:
>$ indent -kr -ppi 3 -st your_file.c
Which version of indent are you using?
Mine, on FreeBSD-6.2-STABLE doesn't have any of the options you're
using...
$ indent --version
GNU indent 2.2.9
The laptop is running Ubuntu 7.04 Feisty.
--
Tor <torust [at] online [dot] no> This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Trying_Harder |
last post by:
Is it possible to redefine a macro with global scope after
undefining it in a function? If yes, could someone explain
how?
/If/ my question above isn't very clear you can refer to
the following example.
eg cosider 2 files sample.c and sample.h
sample.h
|
by: Jim Ford |
last post by:
I have a single C file with the following code:
int f2()
{
/* Blah-blah */
}
int f1()
{
/* Blah-blah */
|
by: seemanta dutta |
last post by:
Greetings C gurus,
I have used preprocessor directives since a very long time. But
whenever I see some professional piece of C code, the linux kernel for
example, I get literally confused by the amount of preprocessor
directives used in these code.
Can anyone please tell me how to actually use these preprocessor
directives in a more professional way like selecting particular lines
of code suited for some particular hardware etc...
|
by: Urs Thuermann |
last post by:
Does a tool exist to apply C preprocessor expansion to a C source only
partially, i.e. replace only some directives? I want to replace some
#if's by their expansions, e.g. all #ifdef SOME_SYMBOL, but keep all
other #ifdef OTHER_SYMBOL and all #include directives.
urs
|
by: Sam of California |
last post by:
Is it accurate to say that "the preprocessor is just a pass in the parsing
of the source file"?
I responded to that comment by saying that the preprocessor is not just a
pass. It processes statements that the compiler does not process. The good
people in the alt.comp.lang.learn.c-c++ newsgroup insist that the
preprocessor is just one of many passes. The preprocessor processes a
grammer unique to the preprocessor and only that grammer.
...
| |
by: lagman |
last post by:
All,
I'm looking for a tool that is able to take my code base (which is
full of preprocessor directives) and spit out source code that is
"clean" of any preprocessor directives based on the options I choose
(possibly via some kind of user input screen).
Does such a tool exist? A Visual Studio plugin would be even better.
FYI: I have requirements to rid my code of all conditionally compiled
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
| |
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
| |