Talk:Typedef

message: Can anyone tell me what 
typedef uint32 A;
would do  ?
It would create a new type named 'A' that would essentially just be an alias for uint32. You could then create variables like this: 'A newvariables = 3;' Jaddle 17:06, 14 May 2007 (UTC)
replies: text: = 3 --193.136.128.14 13:12, 17 May 2007 (UTC)
thread_title:  typedef uint32 A; 

message: Instead of
typedef int (*ImagePointer)[3];
is it legal and equivalent to write
typedef int (*)[3] ImagePointer;
If I haven't screwed it up, the latter is the notation that would be used in C-style casting.  I think the article should mention whether or not this is legal and equivalent.  Thank you. Quantling (talk) 15:32, 14 April 2010 (UTC)
replies: text: No, the latter is not a legal typedef. You're correct that (int (*)[3]) would be used in C-style cast notation. decltype (talk) 10:14, 29 April 2010 (UTC)
thread_title:  Use of casting notation? 

message: In the "Indicating what a variable represents" section typedefs are used to indicate to the programmer that two values, both implemented as ints, are not the same semantically.  However, these typedefs do not also indicate this to the compiler ; C/C++ compilers will allow free "conversion" between variables of these two types as if they were both declared simply as ints.  At least this is the case with the compilers I have tried, and I know of no simple way to get a compiler to enforce type checking in this scenario.  To the extent that I have this right, should any of it be added to the article? --Quantling (talk) 18:34, 29 April 2010 (UTC)
replies: text: You're right, the example is misleading in that it seems to indicate that typedefs are something they're not - that they will provide some sort of type checking. A common(?) misconception. decltype (talk) 18:52, 29 April 2010 (UTC)

text: This has nothing to do with typedefs though. Each struct always creates a new type (even if it is not named). Compatibility between structs is never determined by "identical looking"-ness. --169.232.246.212 (talk) 08:43, 30 April 2010 (UTC)
thread_title:  <code>typedef</code> does not create a type 

message: Regarding
 08:46, 30 April 2010 169.232.246.212 (talk | block) (7,474 bytes) (Undid revision 359028539 by Decltype (talk) what part of this is incorrect?) (rollback | undo) 
 (cur | prev)  09:58, 29 April 2010 Decltype (talk | contribs | block) (6,874 bytes) (→Using typedef with pointers: rm misinformation) (undo) 
The text was:
Note that a struct declaration in C++ also defines an implicit typedef—that is, the data type can be referred to as var (rather than struct var) immediately, without any explicit use of the typedef keyword. However, even in C++ it can be worthwhile to define typedefs for more complicated types. For example, a program to manipulate RGB images might find it useful to give the name ImagePointer to the type "pointer to array[3] of int":
I removed the information because it incorrectly asserts that a struct declaration in C++ defines an implicit typedef, which has no basis in the language. Instead, C++, allows you to omit the class-key in an object declaration. The ImagePointer example, the way I see it, is just original research unless backed by a source - especially considering that typedeffing pointer types is often discouraged in C++. decltype (talk) 09:44, 30 April 2010 (UTC)
replies: text: I guess the point of the first part was that in C, the only way to introduce a new single-word type identifier was using typedef. But in C++, struct, class, enum, etc. can also introduce new single-word type identifiers. So from the perspective of C, it is as if each of these did a typedef. But, on a second look, it seems that this is already covered in the "Simplifying a declaration" section. So feel free to remove it again I guess. --169.232.246.183 (talk) 20:11, 2 May 2010 (UTC)
thread_title:  reversion 

message: What I'm really missing is the general syntax of the typedef keyword.
Can anyone copy it from a C book and paste it here?
After searching a while, I found the following syntax definition:
typedef type-definition identifier;
This syntax definition is wrong. It just happens to lead to a correct result in a subset of cases, but that is not how typedef is defined. This blog entry explains it:
https://mpark.github.io/programming/2016/05/12/typedef-literacy/
JonKalb (talk) 16:48, 18 June 2016 (UTC)
thread_title:  Syntax 

message: Strictly, POSIX specifies that typedef names ending in _t are reserved for use by standards only. User code should never typedef anything ending in _t (since doing so may cause overlap with later revisions of POSIX etc.), and the standards certainly do not recommend doing so, despite this being a common practice today in system-level software.
The paragraph should be modified to reflect this. At the very least it shouldn't propagate a false recommendation!  — Preceding unsigned comment added by 88.192.76.31 (talk) 15:37, 4 November 2016 (UTC)
thread_title:  First paragraph is incorrect wrt standards 

message: Bennnnnn 78.182.222.153 (talk) 20:35, 10 September 2022 (UTC)
thread_title:  Fguu