找回密码
 注册
搜索
热搜: 回贴
  • 前程无忧官网首页 有什么好的平台可以
  • 最新的销售平台 互联网营销的平台有哪
  • 制作网页的基本流程 网页制作和网页设
  • 【帝国CMS】输出带序号的列表(数字排
  • 网站建设公司 三一,中联,极东泵车的
  • 织梦 建站 织梦网站模版后台怎么更改
  • 云服务官网 哪些网站有免费的简历模板
  • 如何建网站要什么条件 建网站要用什么
  • 吉林市移动公司电话 吉林省退休人员网
  • 设计类毕业论文 网站设计与实现毕业论
查看: 931|回复: 9

求助:程序中的code是什么意思?

[复制链接]
发表于 2009-11-2 02:06:22 | 显示全部楼层 |阅读模式 IP:江苏扬州
小弟是个新手,在学习单片机c语言中遇到这样的东西,实在不知道是什么意思:
typedef code struct
{ }结构名;
typedef code BYTE aa;
还有就是在函数的前面加一个code. typedef我到是能明白,但是code的用法却不清楚,不知道在这些地方code的作用是什么??希望大家能帮忙说一下,谢谢
发表于 2009-11-2 02:06:28 | 显示全部楼层 IP:江苏扬州
我见过

typedef struct code{}结构名;

这种格式的。楼主的这种格式是否也是一样呢?
回复

使用道具 举报

发表于 2009-11-2 02:06:33 | 显示全部楼层 IP:江苏扬州
差不多的,只是换了一下而已,就是

typedef code struct
{ }结构名;
但你说的那个code我也不知道是什么意思。你是否可以告诉下?
回复

使用道具 举报

发表于 2009-11-2 02:06:39 | 显示全部楼层 IP:江苏扬州
我说的那个就是 struct的名字。
一般我们定义struct的时候都是
struct code
{
string id;
……
}

void f()
{
code cd;
cd.id = "C1";
}
这样子用。

这里 typedef struct code{}结构名,就是给这个struct又起了个别名,叫结构名
回复

使用道具 举报

发表于 2009-11-2 02:06:45 | 显示全部楼层 IP:江苏扬州
你说的是这个结构的名称就是code,是吧。
其实我说的这个东西是的原来的代码是这样的:
typedef code struct {
configuration_descriptor hid_configuration_descriptor;
interface_descriptor hid_interface_descriptor;
class_descriptor hid_descriptor;
endpoint_descriptor hid_endpoint_in_descriptor;
endpoint_descriptor hid_endpoint_out_descriptor;
}
hid_configuration_descriptor;
是别人在开发USB时定义的一种结构,但是我实在是不知道code的作用,去掉后编译就不能通过。
还有我上面说的另外的两种情况中code的意思,我也不清楚。
回复

使用道具 举报

发表于 2009-11-2 02:06:51 | 显示全部楼层 IP:江苏扬州
这个结构里面本身包含了hid_configuration_descriptor这种数据类型,然后又定义了这样的一种结构,code是不是有特别的意思?
回复

使用道具 举报

发表于 2009-11-2 02:06:57 | 显示全部楼层 IP:江苏扬州
code是不是自定义的数据类型?不过没见过这种用法。

一个结构本身可以包含自己结构的指针。你的代码里结构里的hid_configuration_descriptor是变量名阿,
configuration_descriptor是它的数据类型。
回复

使用道具 举报

发表于 2009-11-2 02:07:05 | 显示全部楼层 IP:江苏扬州
恩,谢谢。这个东西本身是在头文件中的,我看这样吧,文件本身不大,我把它贴出来,你也能看的清楚点。
#ifndef _USB_DESC_H_
#define _USB_DESC_H_
#ifndef _BYTE_DEF_
#define _BYTE_DEF_
typedef unsigned char BYTE;
#endif

#ifndef _WORD_DEF_ // Compiler Specific, written for Little Endian
#define _WORD_DEF_
typedef union {unsigned int i; unsigned char c[2];} WORD
#define LSB 1 // All words sent to and received from the host are
#define MSB 0 // little endian, this is switched by software when
// neccessary. These sections of code have been marked
// with "Compiler Specific" as above for easier modification
#endif

typedef /*code*/ struct
{
BYTE bLength; // Size of this Descriptor in Bytes 以字节为基本单位
BYTE bDescriptorType; // Descriptor Type (=1)
WORD bcdUSB; // USB Spec Release Number in BCD
BYTE bDeviceClass; // Device Class Code
BYTE bDeviceSubClass; // Device Subclass Code
BYTE bDeviceProtocol; // Device Protocol Code
BYTE bMaxPacketSize0; // Maximum Packet Size for EP0
WORD idVendor; // Vendor ID
WORD idProduct; // Product ID
WORD bcdDevice; // Device Release Number in BCD
BYTE iManufacturer; // Index of String Desc for Manufacturer
BYTE iProduct; // Index of String Desc for Product
BYTE iSerialNumber; // Index of String Desc for SerNo
BYTE bNumConfigurations; // Number of possible Configurations
} device_descriptor; // End of Device Descriptor Type
//--------------------------------------------------
// Standard Configuration Descriptor Type Definition
//--------------------------------------------------
typedef /*code*/ struct
{
BYTE bLength; // Size of this Descriptor in Bytes
BYTE bDescriptorType; // Descriptor Type (=2)
WORD wTotalLength; // Total Length of Data for this Conf
BYTE bNumInterfaces; // No of Interfaces supported by this Conf
BYTE bConfigurationValue; // Designator Value for *this* Configuration
BYTE iConfiguration; // Index of String Desc for this Conf
BYTE bmAttributes; // Configuration Characteristics (see below)
BYTE bMaxPower; // Max. Power Consumption in this Conf (*2mA)
} configuration_descriptor; // End of Configuration Descriptor Type
//----------------------------------------------
// Standard Interface Descriptor Type Definition
//----------------------------------------------
typedef /*code*/ struct
{
BYTE bLength; // Size of this Descriptor in Bytes
BYTE bDescriptorType; // Descriptor Type (=4)
BYTE bInterfaceNumber; // Number of *this* Interface (0..)
BYTE bAlternateSetting; // Alternative for this Interface (if any)
BYTE bNumEndpoints; // No of EPs used by this IF (excl. EP0)
BYTE bInterfaceClass; // Interface Class Code
BYTE bInterfaceSubClass; // Interface Subclass Code
BYTE bInterfaceProtocol; // Interface Protocol Code
BYTE iInterface; // Index of String Desc for this Interface
} interface_descriptor; // End of Interface Descriptor Type
//------------------------------------------
// Standard Class Descriptor Type Definition
//------------------------------------------
typedef /*code */struct //
{
BYTE bLength; // Size of this Descriptor in Bytes (=9)
BYTE bDescriptorType; // Descriptor Type (HID=0x21)
WORD bcdHID; // HID Class Specification release number (=1.00)
BYTE bCountryCode; // Localized country code
BYTE bNumDescriptors; // Number of class descriptors to follow
BYTE bReportDescriptorType; // Report descriptor type (HID=0x22)
WORD wItemLength; // Total length of report descriptor table
} class_descriptor; // End of Class Descriptor Type
//---------------------------------------------
// Standard Endpoint Descriptor Type Definition
//---------------------------------------------
typedef /*code*/ struct
{
BYTE bLength; // Size of this Descriptor in Bytes
BYTE bDescriptorType; // Descriptor Type (=5)
BYTE bEndpointAddress; // Endpoint Address (Number + Direction)
BYTE bmAttributes; // Endpoint Attributes (Transfer Type)
WORD wMaxPacketSize; // Max. Endpoint Packet Size
BYTE bInterval; // Polling Interval (Interrupt) ms
} endpoint_descriptor; // End of Endpoint Descriptor Type
//---------------------------------------------
// HID Configuration Descriptor Type Definition
//---------------------------------------------
// From "USB Device Class Definition for Human Interface Devices (HID)".
// Section 7.1:
// "When a Get_Descriptor(Configuration) request is issued,
// it returns the Configuration descriptor, all Interface descriptors,
// all Endpoint descriptors, and the HID descriptor for each interface."
typedef code struct {
configuration_descriptor hid_configuration_descriptor; //HID类设备定义
interface_descriptor hid_interface_descriptor;
class_descriptor hid_descriptor;
endpoint_descriptor hid_endpoint_in_descriptor;
endpoint_descriptor hid_endpoint_out_descriptor;
}
hid_configuration_descriptor;
#define HID_REPORT_DESCRIPTOR_SIZE 0x001B
#define HID_REPORT_DESCRIPTOR_SIZE_LE 0x1B00
typedef code BYTE hid_report_descriptor[HID_REPORT_DESCRIPTOR_SIZE];
//-----------------------------
// Setup Packet Type Definition
//-----------------------------
typedef struct
{
BYTE bmRequestType; // Request recipient, type, and direction
BYTE bRequest; // Specific standard request number
WORD wValue; // varies according to request
WORD wIndex; // varies according to request
WORD wLength; // Number of bytes to transfer
} setup_buffer; // End of Setup Packet Type
#endif

我确实也没有看到有code的定义。另外,在另外的头文件中有
code const BYTE String0Desc[STR0LEN] =
{
STR0LEN, 0x03, 0x09, 0x04
}; 这里的code又是什么意思?都被code给搞糊涂了。
回复

使用道具 举报

发表于 2009-11-2 02:07:13 | 显示全部楼层 IP:江苏扬州
楼主啊,这是源代码么?

code外面分明有注释符阿
/*code*/ 这是被注释掉的阿。
回复

使用道具 举报

发表于 2009-11-2 02:07:21 | 显示全部楼层 IP:江苏扬州
恩,但是有一个是没有被注释的,你再看看那个HID设备类定义的那个。
不知道你是不是在单片机的c中见到过这种用法。象
code const BYTE String0Desc[STR0LEN] =
{
STR0LEN, 0x03, 0x09, 0x04
};
这种的话,不要code也能编译通过,但是就占用的data段多。不知道是不是这样做的话就把常量放在code段了?
但是定义结构的那个,去掉code的话编译就不能通过了。不知道什么意思。
谢谢你!~~
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

QQ|小黑屋|最新主题|手机版|微赢网络技术论坛 ( 苏ICP备08020429号 )

GMT+8, 2024-9-29 23:39 , Processed in 0.196692 second(s), 12 queries , Gzip On, MemCache On.

Powered by Discuz! X3.5

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表