What does typedef with no type mean?












3















From the Standard N1570 6.7.8:




A typedef declaration does not introduce a new type, only a synonym
for the type so specified.




So I expected that it is not possible to write something like this:



typedef t;
t *t_ptr;


and it should fail to compile since no type to introduce a synonym to provided. But it is fine: Demo. So what does this ever mean and why does it compile?










share|improve this question




















  • 3





    It is as fine as MSVC is a fine C compiler, i.e. not fine at all.

    – Antti Haapala
    Nov 28 '18 at 5:33
















3















From the Standard N1570 6.7.8:




A typedef declaration does not introduce a new type, only a synonym
for the type so specified.




So I expected that it is not possible to write something like this:



typedef t;
t *t_ptr;


and it should fail to compile since no type to introduce a synonym to provided. But it is fine: Demo. So what does this ever mean and why does it compile?










share|improve this question




















  • 3





    It is as fine as MSVC is a fine C compiler, i.e. not fine at all.

    – Antti Haapala
    Nov 28 '18 at 5:33














3












3








3


1






From the Standard N1570 6.7.8:




A typedef declaration does not introduce a new type, only a synonym
for the type so specified.




So I expected that it is not possible to write something like this:



typedef t;
t *t_ptr;


and it should fail to compile since no type to introduce a synonym to provided. But it is fine: Demo. So what does this ever mean and why does it compile?










share|improve this question
















From the Standard N1570 6.7.8:




A typedef declaration does not introduce a new type, only a synonym
for the type so specified.




So I expected that it is not possible to write something like this:



typedef t;
t *t_ptr;


and it should fail to compile since no type to introduce a synonym to provided. But it is fine: Demo. So what does this ever mean and why does it compile?







c typedef






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 29 '18 at 20:40









dbush

102k13108144




102k13108144










asked Nov 28 '18 at 5:16









Some NameSome Name

1,517417




1,517417








  • 3





    It is as fine as MSVC is a fine C compiler, i.e. not fine at all.

    – Antti Haapala
    Nov 28 '18 at 5:33














  • 3





    It is as fine as MSVC is a fine C compiler, i.e. not fine at all.

    – Antti Haapala
    Nov 28 '18 at 5:33








3




3





It is as fine as MSVC is a fine C compiler, i.e. not fine at all.

– Antti Haapala
Nov 28 '18 at 5:33





It is as fine as MSVC is a fine C compiler, i.e. not fine at all.

– Antti Haapala
Nov 28 '18 at 5:33












3 Answers
3






active

oldest

votes


















6














This relies on the fact that, missing type specification defaults to int.



So, your statement



 typedef t;


is the same as



 typedef int t;


With the proper level of warning, compiler emits warning:



warning: type defaults to ‘int’ in declaration of ‘t’ [-Wimplicit-int]
typedef t;
^


That said, do not rely on this behaviour, "implicit int" rule has been obsolete since C99.






share|improve this answer


























  • So reasonable to ask if it is Standardized?

    – Some Name
    Nov 28 '18 at 5:23











  • @SomeName it was, 3 decades ago and has not been for 2 decades.

    – Antti Haapala
    Nov 28 '18 at 5:25











  • @AnttiHaapala So now the behavior is undefined or implementation defined?

    – Some Name
    Nov 28 '18 at 5:27






  • 2





    @SomeName neither. A C99, C11, C17 compiler must diagnose this as an incorrect program.

    – Antti Haapala
    Nov 28 '18 at 5:28













  • @SomeName The support itself for implicit int is removed, though it is still provided as compiler extension. Use strict mode , and your code should fail to compile in first place.

    – Sourav Ghosh
    Nov 28 '18 at 5:29





















3














It defaults to an int.



The compiler warning shows what is going on:



#1 with x86-64 gcc 8.2
<source>:1:9: warning: type defaults to 'int' in declaration of 't' [-Wimplicit-int]
typedef t;


From C99 onwards, the implicit int rule was removed. So this is not applicable from C99 onward.



If you use the -pedantic-errors compiler option in GCC (meaning strict conformity to the standard), it issues an error. See here.



If you are interested, the relevant section in C89 standard which allowed this:




3.5.2 Type specifiers

Each list of type specifiers shall be one of the following sets; the type specifiers may occur in any order, possibly intermixed with the other declaration specifiers.




  • void

  • char

  • signed char

  • unsigned char

  • short , signed short , short int , or signed short int

  • unsigned short , or unsigned short int

  • int , signed , signed int , or no type specifiers




So in C99, the last part of what was bolded above (or no type specifiers) was removed.






share|improve this answer





















  • 1





    Please don't confuse readers by quoting now-outdated C89, not everyone may know about the applicability of the standards. :)

    – Sourav Ghosh
    Nov 28 '18 at 5:39













  • I did mention that it is not relevant from C99 onwards. But I can make it extra clear.

    – P.W
    Nov 28 '18 at 5:40











  • I would really appreciate if you move the positioning of the two blocks. First, mention about C99/C11 and then, about C89. Just my two cents.

    – Sourav Ghosh
    Nov 28 '18 at 5:45











  • @SouravGhosh: Done.

    – P.W
    Nov 28 '18 at 5:48



















0














A typedef declaration defines a synonym for an object or pointer type. So you should specify both the type for which you want to create a synonym, and a name to use as synonym.



For example:



// 'byte_t' is a synonym for 'unsigned char'
typedef unsigned char byte_t;
// 'handler_t' is a synonym for 'void (*)(int)', a function pointer
typedef void (*handler_t)(int);
// 'short_p' is a synonym for 'short *'
typedef short * short_p;
// 'record' is a synonym for an anonymous structure
typedef struct {
int a;
char *b;
} record;
// 'error_p' is a synonym for a pointer to 'struct error', defined somewhere else
typedef struct error *error_p;


Many more examples in the source you cited.






share|improve this answer





















  • 1





    This is fine, but how does this answers the question?

    – Sourav Ghosh
    Nov 28 '18 at 5:55











  • @Sourav Ghosh I felt that the typedef syntax was new to him, so I give him some basic examples with comments. Other answers already addressed the compilation problem in itself.

    – A. Semat
    Nov 28 '18 at 6:07











  • Please don't invent your own terms and grammar that don't even exist in the C language. There are no syntax items called "base-type" or "type-alias".

    – Lundin
    Nov 28 '18 at 9:53













  • @Lundin. Thanks. I should have specified that base-type and type-alias should have been replaced by actual types and names. Moreover that pseudo-syntax didn't suit function types. I also changed alias to synonym, since the C standards refers to typedef names as such.

    – A. Semat
    Nov 28 '18 at 10:29











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53512585%2fwhat-does-typedef-with-no-type-mean%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























3 Answers
3






active

oldest

votes








3 Answers
3






active

oldest

votes









active

oldest

votes






active

oldest

votes









6














This relies on the fact that, missing type specification defaults to int.



So, your statement



 typedef t;


is the same as



 typedef int t;


With the proper level of warning, compiler emits warning:



warning: type defaults to ‘int’ in declaration of ‘t’ [-Wimplicit-int]
typedef t;
^


That said, do not rely on this behaviour, "implicit int" rule has been obsolete since C99.






share|improve this answer


























  • So reasonable to ask if it is Standardized?

    – Some Name
    Nov 28 '18 at 5:23











  • @SomeName it was, 3 decades ago and has not been for 2 decades.

    – Antti Haapala
    Nov 28 '18 at 5:25











  • @AnttiHaapala So now the behavior is undefined or implementation defined?

    – Some Name
    Nov 28 '18 at 5:27






  • 2





    @SomeName neither. A C99, C11, C17 compiler must diagnose this as an incorrect program.

    – Antti Haapala
    Nov 28 '18 at 5:28













  • @SomeName The support itself for implicit int is removed, though it is still provided as compiler extension. Use strict mode , and your code should fail to compile in first place.

    – Sourav Ghosh
    Nov 28 '18 at 5:29


















6














This relies on the fact that, missing type specification defaults to int.



So, your statement



 typedef t;


is the same as



 typedef int t;


With the proper level of warning, compiler emits warning:



warning: type defaults to ‘int’ in declaration of ‘t’ [-Wimplicit-int]
typedef t;
^


That said, do not rely on this behaviour, "implicit int" rule has been obsolete since C99.






share|improve this answer


























  • So reasonable to ask if it is Standardized?

    – Some Name
    Nov 28 '18 at 5:23











  • @SomeName it was, 3 decades ago and has not been for 2 decades.

    – Antti Haapala
    Nov 28 '18 at 5:25











  • @AnttiHaapala So now the behavior is undefined or implementation defined?

    – Some Name
    Nov 28 '18 at 5:27






  • 2





    @SomeName neither. A C99, C11, C17 compiler must diagnose this as an incorrect program.

    – Antti Haapala
    Nov 28 '18 at 5:28













  • @SomeName The support itself for implicit int is removed, though it is still provided as compiler extension. Use strict mode , and your code should fail to compile in first place.

    – Sourav Ghosh
    Nov 28 '18 at 5:29
















6












6








6







This relies on the fact that, missing type specification defaults to int.



So, your statement



 typedef t;


is the same as



 typedef int t;


With the proper level of warning, compiler emits warning:



warning: type defaults to ‘int’ in declaration of ‘t’ [-Wimplicit-int]
typedef t;
^


That said, do not rely on this behaviour, "implicit int" rule has been obsolete since C99.






share|improve this answer















This relies on the fact that, missing type specification defaults to int.



So, your statement



 typedef t;


is the same as



 typedef int t;


With the proper level of warning, compiler emits warning:



warning: type defaults to ‘int’ in declaration of ‘t’ [-Wimplicit-int]
typedef t;
^


That said, do not rely on this behaviour, "implicit int" rule has been obsolete since C99.







share|improve this answer














share|improve this answer



share|improve this answer








edited Nov 28 '18 at 5:52

























answered Nov 28 '18 at 5:22









Sourav GhoshSourav Ghosh

111k15131190




111k15131190













  • So reasonable to ask if it is Standardized?

    – Some Name
    Nov 28 '18 at 5:23











  • @SomeName it was, 3 decades ago and has not been for 2 decades.

    – Antti Haapala
    Nov 28 '18 at 5:25











  • @AnttiHaapala So now the behavior is undefined or implementation defined?

    – Some Name
    Nov 28 '18 at 5:27






  • 2





    @SomeName neither. A C99, C11, C17 compiler must diagnose this as an incorrect program.

    – Antti Haapala
    Nov 28 '18 at 5:28













  • @SomeName The support itself for implicit int is removed, though it is still provided as compiler extension. Use strict mode , and your code should fail to compile in first place.

    – Sourav Ghosh
    Nov 28 '18 at 5:29





















  • So reasonable to ask if it is Standardized?

    – Some Name
    Nov 28 '18 at 5:23











  • @SomeName it was, 3 decades ago and has not been for 2 decades.

    – Antti Haapala
    Nov 28 '18 at 5:25











  • @AnttiHaapala So now the behavior is undefined or implementation defined?

    – Some Name
    Nov 28 '18 at 5:27






  • 2





    @SomeName neither. A C99, C11, C17 compiler must diagnose this as an incorrect program.

    – Antti Haapala
    Nov 28 '18 at 5:28













  • @SomeName The support itself for implicit int is removed, though it is still provided as compiler extension. Use strict mode , and your code should fail to compile in first place.

    – Sourav Ghosh
    Nov 28 '18 at 5:29



















So reasonable to ask if it is Standardized?

– Some Name
Nov 28 '18 at 5:23





So reasonable to ask if it is Standardized?

– Some Name
Nov 28 '18 at 5:23













@SomeName it was, 3 decades ago and has not been for 2 decades.

– Antti Haapala
Nov 28 '18 at 5:25





@SomeName it was, 3 decades ago and has not been for 2 decades.

– Antti Haapala
Nov 28 '18 at 5:25













@AnttiHaapala So now the behavior is undefined or implementation defined?

– Some Name
Nov 28 '18 at 5:27





@AnttiHaapala So now the behavior is undefined or implementation defined?

– Some Name
Nov 28 '18 at 5:27




2




2





@SomeName neither. A C99, C11, C17 compiler must diagnose this as an incorrect program.

– Antti Haapala
Nov 28 '18 at 5:28







@SomeName neither. A C99, C11, C17 compiler must diagnose this as an incorrect program.

– Antti Haapala
Nov 28 '18 at 5:28















@SomeName The support itself for implicit int is removed, though it is still provided as compiler extension. Use strict mode , and your code should fail to compile in first place.

– Sourav Ghosh
Nov 28 '18 at 5:29







@SomeName The support itself for implicit int is removed, though it is still provided as compiler extension. Use strict mode , and your code should fail to compile in first place.

– Sourav Ghosh
Nov 28 '18 at 5:29















3














It defaults to an int.



The compiler warning shows what is going on:



#1 with x86-64 gcc 8.2
<source>:1:9: warning: type defaults to 'int' in declaration of 't' [-Wimplicit-int]
typedef t;


From C99 onwards, the implicit int rule was removed. So this is not applicable from C99 onward.



If you use the -pedantic-errors compiler option in GCC (meaning strict conformity to the standard), it issues an error. See here.



If you are interested, the relevant section in C89 standard which allowed this:




3.5.2 Type specifiers

Each list of type specifiers shall be one of the following sets; the type specifiers may occur in any order, possibly intermixed with the other declaration specifiers.




  • void

  • char

  • signed char

  • unsigned char

  • short , signed short , short int , or signed short int

  • unsigned short , or unsigned short int

  • int , signed , signed int , or no type specifiers




So in C99, the last part of what was bolded above (or no type specifiers) was removed.






share|improve this answer





















  • 1





    Please don't confuse readers by quoting now-outdated C89, not everyone may know about the applicability of the standards. :)

    – Sourav Ghosh
    Nov 28 '18 at 5:39













  • I did mention that it is not relevant from C99 onwards. But I can make it extra clear.

    – P.W
    Nov 28 '18 at 5:40











  • I would really appreciate if you move the positioning of the two blocks. First, mention about C99/C11 and then, about C89. Just my two cents.

    – Sourav Ghosh
    Nov 28 '18 at 5:45











  • @SouravGhosh: Done.

    – P.W
    Nov 28 '18 at 5:48
















3














It defaults to an int.



The compiler warning shows what is going on:



#1 with x86-64 gcc 8.2
<source>:1:9: warning: type defaults to 'int' in declaration of 't' [-Wimplicit-int]
typedef t;


From C99 onwards, the implicit int rule was removed. So this is not applicable from C99 onward.



If you use the -pedantic-errors compiler option in GCC (meaning strict conformity to the standard), it issues an error. See here.



If you are interested, the relevant section in C89 standard which allowed this:




3.5.2 Type specifiers

Each list of type specifiers shall be one of the following sets; the type specifiers may occur in any order, possibly intermixed with the other declaration specifiers.




  • void

  • char

  • signed char

  • unsigned char

  • short , signed short , short int , or signed short int

  • unsigned short , or unsigned short int

  • int , signed , signed int , or no type specifiers




So in C99, the last part of what was bolded above (or no type specifiers) was removed.






share|improve this answer





















  • 1





    Please don't confuse readers by quoting now-outdated C89, not everyone may know about the applicability of the standards. :)

    – Sourav Ghosh
    Nov 28 '18 at 5:39













  • I did mention that it is not relevant from C99 onwards. But I can make it extra clear.

    – P.W
    Nov 28 '18 at 5:40











  • I would really appreciate if you move the positioning of the two blocks. First, mention about C99/C11 and then, about C89. Just my two cents.

    – Sourav Ghosh
    Nov 28 '18 at 5:45











  • @SouravGhosh: Done.

    – P.W
    Nov 28 '18 at 5:48














3












3








3







It defaults to an int.



The compiler warning shows what is going on:



#1 with x86-64 gcc 8.2
<source>:1:9: warning: type defaults to 'int' in declaration of 't' [-Wimplicit-int]
typedef t;


From C99 onwards, the implicit int rule was removed. So this is not applicable from C99 onward.



If you use the -pedantic-errors compiler option in GCC (meaning strict conformity to the standard), it issues an error. See here.



If you are interested, the relevant section in C89 standard which allowed this:




3.5.2 Type specifiers

Each list of type specifiers shall be one of the following sets; the type specifiers may occur in any order, possibly intermixed with the other declaration specifiers.




  • void

  • char

  • signed char

  • unsigned char

  • short , signed short , short int , or signed short int

  • unsigned short , or unsigned short int

  • int , signed , signed int , or no type specifiers




So in C99, the last part of what was bolded above (or no type specifiers) was removed.






share|improve this answer















It defaults to an int.



The compiler warning shows what is going on:



#1 with x86-64 gcc 8.2
<source>:1:9: warning: type defaults to 'int' in declaration of 't' [-Wimplicit-int]
typedef t;


From C99 onwards, the implicit int rule was removed. So this is not applicable from C99 onward.



If you use the -pedantic-errors compiler option in GCC (meaning strict conformity to the standard), it issues an error. See here.



If you are interested, the relevant section in C89 standard which allowed this:




3.5.2 Type specifiers

Each list of type specifiers shall be one of the following sets; the type specifiers may occur in any order, possibly intermixed with the other declaration specifiers.




  • void

  • char

  • signed char

  • unsigned char

  • short , signed short , short int , or signed short int

  • unsigned short , or unsigned short int

  • int , signed , signed int , or no type specifiers




So in C99, the last part of what was bolded above (or no type specifiers) was removed.







share|improve this answer














share|improve this answer



share|improve this answer








edited Nov 28 '18 at 5:48

























answered Nov 28 '18 at 5:23









P.WP.W

16.7k41455




16.7k41455








  • 1





    Please don't confuse readers by quoting now-outdated C89, not everyone may know about the applicability of the standards. :)

    – Sourav Ghosh
    Nov 28 '18 at 5:39













  • I did mention that it is not relevant from C99 onwards. But I can make it extra clear.

    – P.W
    Nov 28 '18 at 5:40











  • I would really appreciate if you move the positioning of the two blocks. First, mention about C99/C11 and then, about C89. Just my two cents.

    – Sourav Ghosh
    Nov 28 '18 at 5:45











  • @SouravGhosh: Done.

    – P.W
    Nov 28 '18 at 5:48














  • 1





    Please don't confuse readers by quoting now-outdated C89, not everyone may know about the applicability of the standards. :)

    – Sourav Ghosh
    Nov 28 '18 at 5:39













  • I did mention that it is not relevant from C99 onwards. But I can make it extra clear.

    – P.W
    Nov 28 '18 at 5:40











  • I would really appreciate if you move the positioning of the two blocks. First, mention about C99/C11 and then, about C89. Just my two cents.

    – Sourav Ghosh
    Nov 28 '18 at 5:45











  • @SouravGhosh: Done.

    – P.W
    Nov 28 '18 at 5:48








1




1





Please don't confuse readers by quoting now-outdated C89, not everyone may know about the applicability of the standards. :)

– Sourav Ghosh
Nov 28 '18 at 5:39







Please don't confuse readers by quoting now-outdated C89, not everyone may know about the applicability of the standards. :)

– Sourav Ghosh
Nov 28 '18 at 5:39















I did mention that it is not relevant from C99 onwards. But I can make it extra clear.

– P.W
Nov 28 '18 at 5:40





I did mention that it is not relevant from C99 onwards. But I can make it extra clear.

– P.W
Nov 28 '18 at 5:40













I would really appreciate if you move the positioning of the two blocks. First, mention about C99/C11 and then, about C89. Just my two cents.

– Sourav Ghosh
Nov 28 '18 at 5:45





I would really appreciate if you move the positioning of the two blocks. First, mention about C99/C11 and then, about C89. Just my two cents.

– Sourav Ghosh
Nov 28 '18 at 5:45













@SouravGhosh: Done.

– P.W
Nov 28 '18 at 5:48





@SouravGhosh: Done.

– P.W
Nov 28 '18 at 5:48











0














A typedef declaration defines a synonym for an object or pointer type. So you should specify both the type for which you want to create a synonym, and a name to use as synonym.



For example:



// 'byte_t' is a synonym for 'unsigned char'
typedef unsigned char byte_t;
// 'handler_t' is a synonym for 'void (*)(int)', a function pointer
typedef void (*handler_t)(int);
// 'short_p' is a synonym for 'short *'
typedef short * short_p;
// 'record' is a synonym for an anonymous structure
typedef struct {
int a;
char *b;
} record;
// 'error_p' is a synonym for a pointer to 'struct error', defined somewhere else
typedef struct error *error_p;


Many more examples in the source you cited.






share|improve this answer





















  • 1





    This is fine, but how does this answers the question?

    – Sourav Ghosh
    Nov 28 '18 at 5:55











  • @Sourav Ghosh I felt that the typedef syntax was new to him, so I give him some basic examples with comments. Other answers already addressed the compilation problem in itself.

    – A. Semat
    Nov 28 '18 at 6:07











  • Please don't invent your own terms and grammar that don't even exist in the C language. There are no syntax items called "base-type" or "type-alias".

    – Lundin
    Nov 28 '18 at 9:53













  • @Lundin. Thanks. I should have specified that base-type and type-alias should have been replaced by actual types and names. Moreover that pseudo-syntax didn't suit function types. I also changed alias to synonym, since the C standards refers to typedef names as such.

    – A. Semat
    Nov 28 '18 at 10:29
















0














A typedef declaration defines a synonym for an object or pointer type. So you should specify both the type for which you want to create a synonym, and a name to use as synonym.



For example:



// 'byte_t' is a synonym for 'unsigned char'
typedef unsigned char byte_t;
// 'handler_t' is a synonym for 'void (*)(int)', a function pointer
typedef void (*handler_t)(int);
// 'short_p' is a synonym for 'short *'
typedef short * short_p;
// 'record' is a synonym for an anonymous structure
typedef struct {
int a;
char *b;
} record;
// 'error_p' is a synonym for a pointer to 'struct error', defined somewhere else
typedef struct error *error_p;


Many more examples in the source you cited.






share|improve this answer





















  • 1





    This is fine, but how does this answers the question?

    – Sourav Ghosh
    Nov 28 '18 at 5:55











  • @Sourav Ghosh I felt that the typedef syntax was new to him, so I give him some basic examples with comments. Other answers already addressed the compilation problem in itself.

    – A. Semat
    Nov 28 '18 at 6:07











  • Please don't invent your own terms and grammar that don't even exist in the C language. There are no syntax items called "base-type" or "type-alias".

    – Lundin
    Nov 28 '18 at 9:53













  • @Lundin. Thanks. I should have specified that base-type and type-alias should have been replaced by actual types and names. Moreover that pseudo-syntax didn't suit function types. I also changed alias to synonym, since the C standards refers to typedef names as such.

    – A. Semat
    Nov 28 '18 at 10:29














0












0








0







A typedef declaration defines a synonym for an object or pointer type. So you should specify both the type for which you want to create a synonym, and a name to use as synonym.



For example:



// 'byte_t' is a synonym for 'unsigned char'
typedef unsigned char byte_t;
// 'handler_t' is a synonym for 'void (*)(int)', a function pointer
typedef void (*handler_t)(int);
// 'short_p' is a synonym for 'short *'
typedef short * short_p;
// 'record' is a synonym for an anonymous structure
typedef struct {
int a;
char *b;
} record;
// 'error_p' is a synonym for a pointer to 'struct error', defined somewhere else
typedef struct error *error_p;


Many more examples in the source you cited.






share|improve this answer















A typedef declaration defines a synonym for an object or pointer type. So you should specify both the type for which you want to create a synonym, and a name to use as synonym.



For example:



// 'byte_t' is a synonym for 'unsigned char'
typedef unsigned char byte_t;
// 'handler_t' is a synonym for 'void (*)(int)', a function pointer
typedef void (*handler_t)(int);
// 'short_p' is a synonym for 'short *'
typedef short * short_p;
// 'record' is a synonym for an anonymous structure
typedef struct {
int a;
char *b;
} record;
// 'error_p' is a synonym for a pointer to 'struct error', defined somewhere else
typedef struct error *error_p;


Many more examples in the source you cited.







share|improve this answer














share|improve this answer



share|improve this answer








edited Nov 29 '18 at 20:38

























answered Nov 28 '18 at 5:51









A. SematA. Semat

584




584








  • 1





    This is fine, but how does this answers the question?

    – Sourav Ghosh
    Nov 28 '18 at 5:55











  • @Sourav Ghosh I felt that the typedef syntax was new to him, so I give him some basic examples with comments. Other answers already addressed the compilation problem in itself.

    – A. Semat
    Nov 28 '18 at 6:07











  • Please don't invent your own terms and grammar that don't even exist in the C language. There are no syntax items called "base-type" or "type-alias".

    – Lundin
    Nov 28 '18 at 9:53













  • @Lundin. Thanks. I should have specified that base-type and type-alias should have been replaced by actual types and names. Moreover that pseudo-syntax didn't suit function types. I also changed alias to synonym, since the C standards refers to typedef names as such.

    – A. Semat
    Nov 28 '18 at 10:29














  • 1





    This is fine, but how does this answers the question?

    – Sourav Ghosh
    Nov 28 '18 at 5:55











  • @Sourav Ghosh I felt that the typedef syntax was new to him, so I give him some basic examples with comments. Other answers already addressed the compilation problem in itself.

    – A. Semat
    Nov 28 '18 at 6:07











  • Please don't invent your own terms and grammar that don't even exist in the C language. There are no syntax items called "base-type" or "type-alias".

    – Lundin
    Nov 28 '18 at 9:53













  • @Lundin. Thanks. I should have specified that base-type and type-alias should have been replaced by actual types and names. Moreover that pseudo-syntax didn't suit function types. I also changed alias to synonym, since the C standards refers to typedef names as such.

    – A. Semat
    Nov 28 '18 at 10:29








1




1





This is fine, but how does this answers the question?

– Sourav Ghosh
Nov 28 '18 at 5:55





This is fine, but how does this answers the question?

– Sourav Ghosh
Nov 28 '18 at 5:55













@Sourav Ghosh I felt that the typedef syntax was new to him, so I give him some basic examples with comments. Other answers already addressed the compilation problem in itself.

– A. Semat
Nov 28 '18 at 6:07





@Sourav Ghosh I felt that the typedef syntax was new to him, so I give him some basic examples with comments. Other answers already addressed the compilation problem in itself.

– A. Semat
Nov 28 '18 at 6:07













Please don't invent your own terms and grammar that don't even exist in the C language. There are no syntax items called "base-type" or "type-alias".

– Lundin
Nov 28 '18 at 9:53







Please don't invent your own terms and grammar that don't even exist in the C language. There are no syntax items called "base-type" or "type-alias".

– Lundin
Nov 28 '18 at 9:53















@Lundin. Thanks. I should have specified that base-type and type-alias should have been replaced by actual types and names. Moreover that pseudo-syntax didn't suit function types. I also changed alias to synonym, since the C standards refers to typedef names as such.

– A. Semat
Nov 28 '18 at 10:29





@Lundin. Thanks. I should have specified that base-type and type-alias should have been replaced by actual types and names. Moreover that pseudo-syntax didn't suit function types. I also changed alias to synonym, since the C standards refers to typedef names as such.

– A. Semat
Nov 28 '18 at 10:29


















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53512585%2fwhat-does-typedef-with-no-type-mean%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

A CLEAN and SIMPLE way to add appendices to Table of Contents and bookmarks

Calculate evaluation metrics using cross_val_predict sklearn

Insert data from modal to MySQL (multiple modal on website)