This is the
talk page for discussing improvements to the
Compatibility of C and C++ article. This is not a forum for general discussion of the article's subject. |
Article policies
|
Find sources: Google ( books · news · scholar · free images · WP refs) · FENS · JSTOR · TWL |
![]() | This article is rated C-class on Wikipedia's
content assessment scale. It is of interest to the following WikiProjects: | |||||||||||||||||||||||||||||
|
The term "legal" isn't much used in the C++ standard. However, there are a few notable uses in the C compatibility section. See for instance C.1.5 Clause 7: declarations
“ | Using these specifiers with type declarations is illegal in C++ | ” |
"Valid" / "invalid" is widely used in the context "valid C, invalid in C++". The term "conforming program" is only used in C. The corresponding C++ term is "well-formed program". Because of this, I'm changing back to valid/invalid. decltype ( talk) 14:44, 9 March 2009 (UTC)
E.g., at file scope,
int i;
int i;is valid in C, invalid in C++
— C.1.2 Clause 3: basic concepts
static struct S { // valid C, invalid in C++
int i;
// ...
};
— C.1.5 Clause 7: declarations
Therefore I fail to see why such use would be technically incorrect in the article. decltype ( talk) 18:09, 9 March 2009 (UTC)
I think that the statement that is found in the section about valid C constructs is misleading, if not wrong. The situation in C++ is just more subtle than it is stated: a struct declaration implies an implicit typedef, if there is no other symbol in identifier scope that inhibits it.
In consequence the code in the next section that is meant to demonstrate this behavior is misleading, too. Indeed, the result for C and C++ is different, as is it done here C refers to the global variable and C++ to the type. But if I put the extern declaration into the function, both refer to the integer variable T in the sizeof operator, since then there is already an identifier T in the scope and the implicit typedef will not trigger. Gustedt ( talk) 17:09, 10 September 2010 (UTC)
With Visual Studio 2008/2010, I realized that you can implicitly convert from int** to const int** when compiling as C (/TC), but not as C++ (/TP). The same is true for volatile. In particular, this code works with the former but not the latter:
int** a; const int** b = a;
You can see further discussion at the C++ FAQ Lite. Should this be added? – kentyman ( talk) 16:38, 1 December 2010 (UTC)
That it is not true. There is no problem in C++ in declaring or returning a struct,union and enum in a function. — Preceding unsigned comment added by 89.67.175.56 ( talk) 23:17, 11 November 2012 (UTC)
Wouldn't it be a good idea to use C++ cast operators instead of C-style casts in the C++ examples? -- Antred ( talk) 15:47, 24 September 2013 (UTC)
Hello fellow Wikipedians,
I have just modified one external link on Compatibility of C and C++. Please take a moment to review my edit. If you have any questions, or need the bot to ignore the links, or the page altogether, please visit this simple FaQ for additional information. I made the following changes:
When you have finished reviewing my changes, please set the checked parameter below to true or failed to let others know (documentation at {{
Sourcecheck}}
).
This message was posted before February 2018.
After February 2018, "External links modified" talk page sections are no longer generated or monitored by InternetArchiveBot. No special action is required regarding these talk page notices, other than
regular verification using the archive tool instructions below. Editors
have permission to delete these "External links modified" talk page sections if they want to de-clutter talk pages, but see the
RfC before doing mass systematic removals. This message is updated dynamically through the template {{
source check}}
(last update: 5 June 2024).
Cheers.— cyberbot II Talk to my owner:Online 18:06, 31 March 2016 (UTC)
This is the
talk page for discussing improvements to the
Compatibility of C and C++ article. This is not a forum for general discussion of the article's subject. |
Article policies
|
Find sources: Google ( books · news · scholar · free images · WP refs) · FENS · JSTOR · TWL |
![]() | This article is rated C-class on Wikipedia's
content assessment scale. It is of interest to the following WikiProjects: | |||||||||||||||||||||||||||||
|
The term "legal" isn't much used in the C++ standard. However, there are a few notable uses in the C compatibility section. See for instance C.1.5 Clause 7: declarations
“ | Using these specifiers with type declarations is illegal in C++ | ” |
"Valid" / "invalid" is widely used in the context "valid C, invalid in C++". The term "conforming program" is only used in C. The corresponding C++ term is "well-formed program". Because of this, I'm changing back to valid/invalid. decltype ( talk) 14:44, 9 March 2009 (UTC)
E.g., at file scope,
int i;
int i;is valid in C, invalid in C++
— C.1.2 Clause 3: basic concepts
static struct S { // valid C, invalid in C++
int i;
// ...
};
— C.1.5 Clause 7: declarations
Therefore I fail to see why such use would be technically incorrect in the article. decltype ( talk) 18:09, 9 March 2009 (UTC)
I think that the statement that is found in the section about valid C constructs is misleading, if not wrong. The situation in C++ is just more subtle than it is stated: a struct declaration implies an implicit typedef, if there is no other symbol in identifier scope that inhibits it.
In consequence the code in the next section that is meant to demonstrate this behavior is misleading, too. Indeed, the result for C and C++ is different, as is it done here C refers to the global variable and C++ to the type. But if I put the extern declaration into the function, both refer to the integer variable T in the sizeof operator, since then there is already an identifier T in the scope and the implicit typedef will not trigger. Gustedt ( talk) 17:09, 10 September 2010 (UTC)
With Visual Studio 2008/2010, I realized that you can implicitly convert from int** to const int** when compiling as C (/TC), but not as C++ (/TP). The same is true for volatile. In particular, this code works with the former but not the latter:
int** a; const int** b = a;
You can see further discussion at the C++ FAQ Lite. Should this be added? – kentyman ( talk) 16:38, 1 December 2010 (UTC)
That it is not true. There is no problem in C++ in declaring or returning a struct,union and enum in a function. — Preceding unsigned comment added by 89.67.175.56 ( talk) 23:17, 11 November 2012 (UTC)
Wouldn't it be a good idea to use C++ cast operators instead of C-style casts in the C++ examples? -- Antred ( talk) 15:47, 24 September 2013 (UTC)
Hello fellow Wikipedians,
I have just modified one external link on Compatibility of C and C++. Please take a moment to review my edit. If you have any questions, or need the bot to ignore the links, or the page altogether, please visit this simple FaQ for additional information. I made the following changes:
When you have finished reviewing my changes, please set the checked parameter below to true or failed to let others know (documentation at {{
Sourcecheck}}
).
This message was posted before February 2018.
After February 2018, "External links modified" talk page sections are no longer generated or monitored by InternetArchiveBot. No special action is required regarding these talk page notices, other than
regular verification using the archive tool instructions below. Editors
have permission to delete these "External links modified" talk page sections if they want to de-clutter talk pages, but see the
RfC before doing mass systematic removals. This message is updated dynamically through the template {{
source check}}
(last update: 5 June 2024).
Cheers.— cyberbot II Talk to my owner:Online 18:06, 31 March 2016 (UTC)