Re: how to detect c99 vs c89 (//-comments vs /*-comments)
Then you can use plugins like project.vim or local_vimrc.vim With local_vimrc.vim (I know 2 very similar plugins with this name, I'm maintaining one of them), add a _vimrc_local.vim (the filename expected I couldn't find them.. I've implemented something similar which loads a current working directory vimrc but saves it in .vim/vimrcs/ .. using a simple hash function which just removes the / \\ characters ;) Another option would be to use autocommands.. instead of modlines au pathtoproject *.c set ft=c89 Which is used by project plugins anyway.. This way you can't forget to add the modline.. Marc
Re: how to detect c99 vs c89 (//-comments vs /*-comments)
Hello, Marc Weber [EMAIL PROTECTED] wrote: Then you can use plugins like project.vim or local_vimrc.vim With local_vimrc.vim (I know 2 very similar plugins with this name, I'm maintaining one of them), add a _vimrc_local.vim (the filename expected I couldn't find them.. I've implemented something similar which loads a current working directory vimrc but saves it in .vim/vimrcs/ .. using a simple hash function which just removes the / \\ characters ;) Both should be on sourceforge. Mine can be downloaded from http://www.vim.org/scripts/script.php?script_id=727 and http://hermitte.free.fr/vim/ressources/vimfiles/plugin/local_vimrc.vim (Once again, it seems I forgot to upload the lastest stable version :-( ) Another option would be to use autocommands.. instead of modlines au pathtoproject *.c set ft=c89 I'm not very fond of that kind of artificial filetypes. Mainly because it has side effects with plugins that hardcode their behaviours according to the current filetype. I remember a plugins that do such things ; even if we can tune those 2-3 plugins to tell that we want to use the same behaviour as the one binded to another filetype. It's no big deal. But it is something we must not forget. It can be done with the forwarding ftplugin (the one that sets the comment characters, and that sources c ftplugins). -- Luc Hermitte
Re: how to detect c99 vs c89 (//-comments vs /*-comments)
Hi, In general you cannot detect which version of the standard some C has been written against since C89 code should still compile with a C99 compiler. There are new keywords, but some developers use macros to emulate C99 like features in C89 code. Your best bet is a mode line, possible a good ol' human one as a comment at the top of the file - /* This file developed against C99/C89 [delete as applicable] */ - so that the code is self documenting, and it can be picked up by VIM on loading to set whatever settings you want. shameless_self_promotion While not helping with detecting whether C source is C89 or C99, my alternate C syntax file helps with developing portable C for a particular C standard. http://www.vim.org/scripts/script.php?script_id=234 /shameless_self_promotion TTFN Mike -- Pulse not found: (A)bandon hope, (R)eincarnate, or (I)gnore?
Re: how to detect c99 vs c89 (//-comments vs /*-comments)
We keep hearing about how placing a modeline at the top of the file... Because I work in a multitabbed environment (i.e.: there are more than one tab standard), I have to use a modeline to sort out tabstop and shiftwidth. I put this modeline AT THE BOTTOM of my file where it works just fine and doesn't interfere with the copyright header or anything else going on at the top. As there are also emacs and VSE consumers of these same files, anything Vim-only would constitute an affront to them (the little bastards, hehehe). Just wanted to go on record about how a modeline can be placed at the bottom or the top of a file. Thanks, Russ Mike Williams wrote: Hi, In general you cannot detect which version of the standard some C has been written against since C89 code should still compile with a C99 compiler. There are new keywords, but some developers use macros to emulate C99 like features in C89 code. Your best bet is a mode line, possible a good ol' human one as a comment at the top of the file - /* This file developed against C99/C89 [delete as applicable] */ - so that the code is self documenting, and it can be picked up by VIM on loading to set whatever settings you want. shameless_self_promotion While not helping with detecting whether C source is C89 or C99, my alternate C syntax file helps with developing portable C for a particular C standard. http://www.vim.org/scripts/script.php?script_id=234 /shameless_self_promotion TTFN Mike
Re: how to detect c99 vs c89 (//-comments vs /*-comments)
For my own future reference, could you post an example of your modeline footer that covers all three editors? thanks, gm On Wed, Jun 21, 2006 at 07:48:26AM -0600, Russell Bateman wrote: We keep hearing about how placing a modeline at the top of the file... Because I work in a multitabbed environment (i.e.: there are more than one tab standard), I have to use a modeline to sort out tabstop and shiftwidth. I put this modeline AT THE BOTTOM of my file where it works just fine and doesn't interfere with the copyright header or anything else going on at the top. As there are also emacs and VSE consumers of these same files, anything Vim-only would constitute an affront to them (the little bastards, hehehe). Just wanted to go on record about how a modeline can be placed at the bottom or the top of a file. Thanks, Russ Mike Williams wrote: Hi, In general you cannot detect which version of the standard some C has been written against since C89 code should still compile with a C99 compiler. There are new keywords, but some developers use macros to emulate C99 like features in C89 code. Your best bet is a mode line, possible a good ol' human one as a comment at the top of the file - /* This file developed against C99/C89 [delete as applicable] */ - so that the code is self documenting, and it can be picked up by VIM on loading to set whatever settings you want. shameless_self_promotion While not helping with detecting whether C source is C89 or C99, my alternate C syntax file helps with developing portable C for a particular C standard. http://www.vim.org/scripts/script.php?script_id=234 /shameless_self_promotion TTFN Mike -- + Gregory H. Margo gmargo at yahoo/com, gmail/com, pacbell/net; greg at margofamily/org
Re: how to detect c99 vs c89 (//-comments vs /*-comments)
Sorry for my misunderstanding. You comment just rang a bell with me. There have been times when I was working with dreaded emacs users, and wanted to use one modeline section that covered both vim and emacs, but could never figure out the emacs side. gm On Wed, Jun 21, 2006 at 08:57:25AM -0600, Russell Bateman wrote: Ah, pardon me, I didn't say I had one that covered all three editors, only that I respected the right of non-Vim users not to have to look at my Vim modeline which I put at the bottom. Gregory Margo wrote: For my own future reference, could you post an example of your modeline footer that covers all three editors? thanks, gm On Wed, Jun 21, 2006 at 07:48:26AM -0600, Russell Bateman wrote: We keep hearing about how placing a modeline at the top of the file... Because I work in a multitabbed environment (i.e.: there are more than one tab standard), I have to use a modeline to sort out tabstop and shiftwidth. I put this modeline AT THE BOTTOM of my file where it works just fine and doesn't interfere with the copyright header or anything else going on at the top. As there are also emacs and VSE consumers of these same files, anything Vim-only would constitute an affront to them (the little bastards, hehehe). Just wanted to go on record about how a modeline can be placed at the bottom or the top of a file. Thanks, Russ Mike Williams wrote: Hi, In general you cannot detect which version of the standard some C has been written against since C89 code should still compile with a C99 compiler. There are new keywords, but some developers use macros to emulate C99 like features in C89 code. Your best bet is a mode line, possible a good ol' human one as a comment at the top of the file - /* This file developed against C99/C89 [delete as applicable] */ - so that the code is self documenting, and it can be picked up by VIM on loading to set whatever settings you want. shameless_self_promotion While not helping with detecting whether C source is C89 or C99, my alternate C syntax file helps with developing portable C for a particular C standard. http://www.vim.org/scripts/script.php?script_id=234 /shameless_self_promotion TTFN Mike -- + Gregory H. Margo gmargo at yahoo/com, gmail/com, pacbell/net; greg at margofamily/org
Re: how to detect c99 vs c89 (//-comments vs /*-comments)
Formally speaking, C99 (ISO/IEC 9899:1999) still refers to ANSI C which does not tolerate the C++ style comment operator. If you don't believe me, just pass whatever your compiler's strict ANSI compliance flag is and see if it doesn't croak on them. Back in 1989, ANSI had not yet conceded the standard to the international committee (ISO) and the C++ definition was just emerging, something that ISO would see to. So, the double slashes aren't C at all, but C++. Nevertheless, I use them to write C code with personally except in very formal implementations. Within the context of the C compiler, the distinction is an easily made one via preprocessor tests, but how Vim can make the determination is pretty threadbare as you point out. Obviously, you can make the Vim consumer dictate that in the .vimrc file, but for the guy working on both styles, that's a problem. Maybe the surest and safest approach is the file extension. My best $.02. Russ Yakov Lerner wrote: Some C sources that I have are c99, other are c89. The c99 sources can use //-style comments. The c89 sources can use only /**/-style comments. I'd like to have my commentify macro to use // in c99 sources, and /**/ in c89 sources. But how to tell those two types apart ? Any ideas ? I'm thinking about searching the file for pre-existing //. That's crude but I can't think of anything else. What would be good method to detect c99 vs c89 ? Yakov
Re: how to detect c99 vs c89 (//-comments vs /*-comments)
On 6/20/06, Russell Bateman [EMAIL PROTECTED] wrote: Formally speaking, C99 (ISO/IEC 9899:1999) still refers to ANSI C which does not tolerate the C++ style comment operator. In the draft standard c99 (*1), 6.4.9.2, page 66, // is defined as a comment. Is this something that was changed/removed from the final standard ? Yakov (*1) http://www.open-std.org/JTC1/SC22/WG14/www/docs/n1124.pdf Yakov Lerner wrote: Some C sources that I have are c99, other are c89. The c99 sources can use //-style comments. The c89 sources can use only /**/-style comments. I'd like to have my commentify macro to use // in c99 sources, and /**/ in c89 sources. But how to tell those two types apart ? Any ideas ? I'm thinking about searching the file for pre-existing //. That's crude but I can't think of anything else. What would be good method to detect c99 vs c89 ? Yakov
Re: how to detect c99 vs c89 (//-comments vs /*-comments)
You know, I worked with this formally for years, but it's not impossible that I missed something. The last time I looked at the spec (and I no longer have access to one because I've changed jobs and companies and the thing costs about $250), it seemed to me that it was in the C++ part of the document. I am certain of the strict ANSI compliance thing because I demonstrated it to myself once when it was important to be strictly ANSI compliant in something I was doing (unless things have changed with recent compiler versions). Here, where I work now, we're strictly ANSI compliant and that includes no C++ style comments, but truly, I haven't tested that assertion since I'd get crucified if I did. Maybe I'll try it before checking something in. Russ Yakov Lerner wrote: On 6/20/06, Russell Bateman [EMAIL PROTECTED] wrote: Formally speaking, C99 (ISO/IEC 9899:1999) still refers to ANSI C which does not tolerate the C++ style comment operator. In the draft standard c99 (*1), 6.4.9.2, page 66, // is defined as a comment. Is this something that was changed/removed from the final standard ? Yakov (*1) http://www.open-std.org/JTC1/SC22/WG14/www/docs/n1124.pdf Yakov Lerner wrote: Some C sources that I have are c99, other are c89. The c99 sources can use //-style comments. The c89 sources can use only /**/-style comments. I'd like to have my commentify macro to use // in c99 sources, and /**/ in c89 sources. But how to tell those two types apart ? Any ideas ? I'm thinking about searching the file for pre-existing //. That's crude but I can't think of anything else. What would be good method to detect c99 vs c89 ? Yakov
Re: how to detect c99 vs c89 (//-comments vs /*-comments)
On 6/20/06, Russell Bateman [EMAIL PROTECTED] wrote: it seemed to me that it was in the C++ part of the document. c99 standard does not have any C++ part I am certain of the strict ANSI compliance thing because I demonstrated it to myself once when it was important to be strictly ANSI compliant in Both c99 and c89 are ANSI C standards, but they are different. Are you confusing ANSI C with c89 ANSI C ? If so, then c89 ANSI standard indeed does not have //. c99 ANSI C standard does have //. Additional references: (2) 'gcc -std=c99 -pedantic' accepts //-comments just fine. (3) This page refers to '//' as c99 feature implemented in gcc': http://gcc.gnu.org/gcc-3.4/c99status.html Yakov Yakov Lerner wrote: On 6/20/06, Russell Bateman [EMAIL PROTECTED] wrote: Formally speaking, C99 (ISO/IEC 9899:1999) still refers to ANSI C which does not tolerate the C++ style comment operator. In the draft standard c99 (*1), 6.4.9.2, page 66, // is defined as a comment. Is this something that was changed/removed from the final standard ? Yakov (*1) http://www.open-std.org/JTC1/SC22/WG14/www/docs/n1124.pdf Yakov Lerner wrote: Some C sources that I have are c99, other are c89. The c99 sources can use //-style comments. The c89 sources can use only /**/-style comments. I'd like to have my commentify macro to use // in c99 sources, and /**/ in c89 sources. But how to tell those two types apart ? Any ideas ? I'm thinking about searching the file for pre-existing //. That's crude but I can't think of anything else. What would be good method to detect c99 vs c89 ? Yakov
RE: how to detect c99 vs c89 (//-comments vs /*-comments)
To answer Yakov's question though, and if he wants to abide by the rules that he has provided he could do one of two things, so far as my limited knowledge can tell: 1. Change the file extensions to represent the differences, for example foo.c89 and foo.c99. 2. A nicer way would probably be to use modelines, namely put something like this at the beginning of every file: #if 0 vim:ft=c89 #endif Note my brilliant avoidance of // or /**/ style comments, just to make sure :) In both cases you would then need to do some mapping to tell vim that c(89)9 should highlight and indent things just like c, something which I am sure I could do with a bit of time that I do not currently have. Can anyone tell me why anyone cares about the styles of comments? I understand that it is important to adhere to standards, but I can't work out why comments need to be in one of the two forms. Why not just use // for inline comments and /**/ for function/block comments? Or why not just use preprocessor commands to mask out your comments and avoid all the confusion? (that was a joke, I think) Max -Original Message- From: Russell Bateman [mailto:[EMAIL PROTECTED] Sent: Tuesday, June 20, 2006 9:22 AM To: Yakov Lerner Cc: Vim List Subject: Re: how to detect c99 vs c89 (//-comments vs /*-comments) Well, Yakov, I'm going to bow to you on this one because I don't have a copy of the document to prove otherwise. Maybe the 2001 amendment put // into C or maybe it didn't need to because it was already there. I know that as late as version 6 of CodeWarrior (2001), that compiler's strict ANSI compliance switch did not tolerate C++ commenting. The conclusion to draw is therefore that there is no way for Vim ever to know. Russ Yakov Lerner wrote: On 6/20/06, Russell Bateman [EMAIL PROTECTED] wrote: it seemed to me that it was in the C++ part of the document. c99 standard does not have any C++ part I am certain of the strict ANSI compliance thing because I demonstrated it to myself once when it was important to be strictly ANSI compliant in Both c99 and c89 are ANSI C standards, but they are different. Are you confusing ANSI C with c89 ANSI C ? If so, then c89 ANSI standard indeed does not have //. c99 ANSI C standard does have //. Additional references: (2) 'gcc -std=c99 -pedantic' accepts //-comments just fine. (3) This page refers to '//' as c99 feature implemented in gcc': http://gcc.gnu.org/gcc-3.4/c99status.html Yakov Yakov Lerner wrote: On 6/20/06, Russell Bateman [EMAIL PROTECTED] wrote: Formally speaking, C99 (ISO/IEC 9899:1999) still refers to ANSI C which does not tolerate the C++ style comment operator. In the draft standard c99 (*1), 6.4.9.2, page 66, // is defined as a comment. Is this something that was changed/removed from the final standard ? Yakov (*1) http://www.open-std.org/JTC1/SC22/WG14/www/docs/n1124.pdf Yakov Lerner wrote: Some C sources that I have are c99, other are c89. The c99 sources can use //-style comments. The c89 sources can use only /**/-style comments. I'd like to have my commentify macro to use // in c99 sources, and /**/ in c89 sources. But how to tell those two types apart ? Any ideas ? I'm thinking about searching the file for pre-existing //. That's crude but I can't think of anything else. What would be good method to detect c99 vs c89 ? Yakov
Re: how to detect c99 vs c89 (//-comments vs /*-comments)
Exactly. When coding for myself or for when it doesn't make any difference to anybody, I code exactly as you describe here, Max, for in-line versus block. Max Dyckhoff wrote: To answer Yakov's question though, and if he wants to abide by the rules that he has provided he could do one of two things, so far as my limited knowledge can tell: 1. Change the file extensions to represent the differences, for example foo.c89 and foo.c99. 2. A nicer way would probably be to use modelines, namely put something like this at the beginning of every file: #if 0 vim:ft=c89 #endif Note my brilliant avoidance of // or /**/ style comments, just to make sure :) In both cases you would then need to do some mapping to tell vim that c(89)9 should highlight and indent things just like c, something which I am sure I could do with a bit of time that I do not currently have. Can anyone tell me why anyone cares about the styles of comments? I understand that it is important to adhere to standards, but I can't work out why comments need to be in one of the two forms. Why not just use // for inline comments and /**/ for function/block comments? Or why not just use preprocessor commands to mask out your comments and avoid all the confusion? (that was a joke, I think) Max -Original Message- From: Russell Bateman [mailto:[EMAIL PROTECTED] Sent: Tuesday, June 20, 2006 9:22 AM To: Yakov Lerner Cc: Vim List Subject: Re: how to detect c99 vs c89 (//-comments vs /*-comments) Well, Yakov, I'm going to bow to you on this one because I don't have a copy of the document to prove otherwise. Maybe the 2001 amendment put // into C or maybe it didn't need to because it was already there. I know that as late as version 6 of CodeWarrior (2001), that compiler's strict ANSI compliance switch did not tolerate C++ commenting. The conclusion to draw is therefore that there is no way for Vim ever to know. Russ Yakov Lerner wrote: On 6/20/06, Russell Bateman [EMAIL PROTECTED] wrote: it seemed to me that it was in the C++ part of the document. c99 standard does not have any C++ part I am certain of the strict ANSI compliance thing because I demonstrated it to myself once when it was important to be strictly ANSI compliant in Both c99 and c89 are ANSI C standards, but they are different. Are you confusing ANSI C with c89 ANSI C ? If so, then c89 ANSI standard indeed does not have //. c99 ANSI C standard does have //. Additional references: (2) 'gcc -std=c99 -pedantic' accepts //-comments just fine. (3) This page refers to '//' as c99 feature implemented in gcc': http://gcc.gnu.org/gcc-3.4/c99status.html Yakov Yakov Lerner wrote: On 6/20/06, Russell Bateman [EMAIL PROTECTED] wrote: Formally speaking, C99 (ISO/IEC 9899:1999) still refers to ANSI C which does not tolerate the C++ style comment operator. In the draft standard c99 (*1), 6.4.9.2, page 66, // is defined as a comment. Is this something that was changed/removed from the final standard ? Yakov (*1) http://www.open-std.org/JTC1/SC22/WG14/www/docs/n1124.pdf Yakov Lerner wrote: Some C sources that I have are c99, other are c89. The c99 sources can use //-style comments. The c89 sources can use only /**/-style comments. I'd like to have my commentify macro to use // in c99 sources, and /**/ in c89 sources. But how to tell those two types apart ? Any ideas ? I'm thinking about searching the file for pre-existing //. That's crude but I can't think of anything else. What would be good method to detect c99 vs c89 ? Yakov
RE: how to detect c99 vs c89 (//-comments vs /*-comments)
I'm sorry, I suppose I should have asked why use c89 at all? :) Did you try the suggestion that I made, or is it not appropriate? If not, how do you, as a human being, identify between the c89 and the c99 source files? Max -Original Message- From: Yakov Lerner [mailto:[EMAIL PROTECTED] Sent: Tuesday, June 20, 2006 11:35 AM To: Max Dyckhoff Cc: Russell Bateman; Vim List Subject: Re: how to detect c99 vs c89 (//-comments vs /*-comments) On 6/20/06, Max Dyckhoff [EMAIL PROTECTED] wrote: Can anyone tell me why anyone cares about the styles of comments? I understand that it is important to adhere to standards, but I can't work out why comments need to be in one of the two forms. Why not just use // for inline comments and /**/ for function/block comments? Because c89 does not have //-comments. This rule you suggested is fine for c99, but it does not work for c89. The modified form of your rule would be For c89, always use /**/. For c99, use // for ..., and /**/ for But then I need the script to know c89 from c99. Yakov
Re: how to detect c99 vs c89 (//-comments vs /*-comments)
On 6/20/06, Max Dyckhoff [EMAIL PROTECTED] wrote: I'm sorry, I suppose I should have asked why use c89 at all? :) c89 is considerably more portable than c99. Out of popular compilers, only gcc implements c99 (I know only gcc and VC). c99 is still largely ignored by some commercial compiler, notably VC. If you want your C code to be widely portable, you'd avoid c99, for practical reasons. Did you try the suggestion that I made, or is it not appropriate? Changing extension to .c89/.c99 is not an option. gcc even does not understand such file extensions, only *.c If not, how do you, as a human being, identify between the c89 and the c99 source files? This is per-project. Some projects are c99. Some porjects are c89. File extensions for both are *.c Yakov
RE: how to detect c99 vs c89 (//-comments vs /*-comments)
c89 is considerably more portable than c99. Out of popular compilers, only gcc implements c99 (I know only gcc and VC). c99 is still largely ignored by some commercial compiler, notably VC. If you want your C code to be widely portable, you'd avoid c99, for practical reasons. How interesting, you learn something new every day! Did you try the suggestion that I made, or is it not appropriate? Changing extension to .c89/.c99 is not an option. gcc even does not understand such file extensions, only *.c What about my modeline suggestion then? Max
Re: how to detect c99 vs c89 (//-comments vs /*-comments)
On 6/20/06, Max Dyckhoff [EMAIL PROTECTED] wrote: Can anyone tell me why anyone cares about the styles of comments? I understand that it is important to adhere to standards, but I can't work out why comments need to be in one of the two forms. Why not just use // for inline comments and /**/ for function/block comments? Because c89 does not have //-comments. This rule you suggested is fine for c99, but it does not work for c89. The modified form of your rule would be For c89, always use /**/. For c99, use // for ..., and /**/ for But then I need the script to know c89 from c99. Yakov
Re: how to detect c99 vs c89 (//-comments vs /*-comments)
I can confirm that Yakov is correct; the // is allowed in C99, and not in the older standard. FYI, the C99 standard (ISO/IEC 9899-1999) is available on Amazon or Bookpool, and probably other sites, for about $75 list. http://www.amazon.com/gp/product/0470845732/ref=sr_11_1/102-4132906-9254519?%5Fencoding=UTF8 http://www.bookpool.com/sm/0470845732 I don't know if the older standard (ANSI X3.159-1989) is still available anywhere. It's a shame really. Everyone should have it right next to the KR. In the end though, IMHO, if you're writing C code you should use the /**/ syntax. If you have a choice, always code for maximum portability and maintainability. gm On Tue, Jun 20, 2006 at 10:02:09AM -0600, Russell Bateman wrote: You know, I worked with this formally for years, but it's not impossible that I missed something. The last time I looked at the spec (and I no longer have access to one because I've changed jobs and companies and the thing costs about $250), it seemed to me that it was in the C++ part of the document. I am certain of the strict ANSI compliance thing because I demonstrated it to myself once when it was important to be strictly ANSI compliant in something I was doing (unless things have changed with recent compiler versions). Here, where I work now, we're strictly ANSI compliant and that includes no C++ style comments, but truly, I haven't tested that assertion since I'd get crucified if I did. Maybe I'll try it before checking something in. Russ Yakov Lerner wrote: On 6/20/06, Russell Bateman [EMAIL PROTECTED] wrote: Formally speaking, C99 (ISO/IEC 9899:1999) still refers to ANSI C which does not tolerate the C++ style comment operator. In the draft standard c99 (*1), 6.4.9.2, page 66, // is defined as a comment. Is this something that was changed/removed from the final standard ? Yakov (*1) http://www.open-std.org/JTC1/SC22/WG14/www/docs/n1124.pdf Yakov Lerner wrote: Some C sources that I have are c99, other are c89. The c99 sources can use //-style comments. The c89 sources can use only /**/-style comments. I'd like to have my commentify macro to use // in c99 sources, and /**/ in c89 sources. But how to tell those two types apart ? Any ideas ? I'm thinking about searching the file for pre-existing //. That's crude but I can't think of anything else. What would be good method to detect c99 vs c89 ? Yakov -- + Gregory H. Margo gmargo at yahoo/com, gmail/com, pacbell/net; greg at margofamily/org