基本的typedef操作语法 [英] Fundamental typedef operand syntax

查看:115
本文介绍了基本的typedef操作语法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设:

typedef type-declaration synonym;

我可以看到:

typedef long unsigned int size_t;

声明为size_t 的代名词长的无符号整型,但是我(知道它,但)不能看的究竟的方法如下:

declares size_t as a synonym for long unsigned int, however I (know it does but) can't see exactly how:

typedef int (*F)(size_t, size_t);

声明˚F作为一个同义词函数指针(为size_t,为size_t)返回int

的typedef的两个操作数(类型声明,同义词)在第一个例子是长的无符号整数为size_t

typedef's two operands (type-declaration, synonym) in the first example are long unsigned int and size_t.

什么是两个参数在˚F或声明的typedef是否有可能超载的typedef的版本?

What are the two arguments to typedef in the declaration of F or are there perhaps overloaded versions of typedef?

如果有C和C之间的相关区别++请详细说明,否则我是用C主要兴趣++是否有帮助。

If there is a relevant distinction between C and C++ please elaborate otherwise I'm primarily interested in C++ if that helps.

推荐答案

使用的typedef 类型声明相同相应的变量声明,只需用的typedef prepended。因此,

Type declarations using typedef are the same as corresponding variable declarations, just with typedef prepended. So,

        int x; // declares a variable named 'x' of type 'int'
typedef int x; // declares a type named 'x' that is 'int'

这正好与函数指针类型相同的:

It's exactly the same with function pointer types:

        int(*F)(size_t); // declares a variable named F of type 'int(*)(size_t)'
typedef int(*F)(size_t); // declares a type named 'F' that is 'int(*)(size_t)'

这不是一个特殊情况;这只是一个函数指针类型是什么样子。

It's not a "special case;" that's just what a function pointer type looks like.

这篇关于基本的typedef操作语法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆