| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 13064 人关注过本帖
标题:求助:程序中的code是什么意思?
只看楼主 加入收藏
cf2000
Rank: 1
等 级:新手上路
帖 子:8
专家分:0
注 册:2006-2-22
收藏
 问题点数:0 回复次数:16 
求助:程序中的code是什么意思?

小弟是个新手,在学习单片机c语言中遇到这样的东西,实在不知道是什么意思:

typedef code struct

{ }结构名;

typedef code BYTE aa;

还有就是在函数的前面加一个code. typedef我到是能明白,但是code的用法却不清楚,不知道在这些地方code的作用是什么??希望大家能帮忙说一下,谢谢

搜索更多相关主题的帖子: code 单片机 typedef 
2006-02-22 09:23
柳儿
Rank: 6Rank: 6
等 级:贵宾
威 望:25
帖 子:1830
专家分:30
注 册:2004-9-23
收藏
得分:0 
我见过

typedef struct code{}结构名;

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

成功会使人骄傲。如果你骄傲自大,你就会停止学习。不学习,人就停止了进步
2006-02-22 10:03
cf2000
Rank: 1
等 级:新手上路
帖 子:8
专家分:0
注 册:2006-2-22
收藏
得分:0 
差不多的,只是换了一下而已,就是

typedef code struct

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

2006-02-22 10:38
柳儿
Rank: 6Rank: 6
等 级:贵宾
威 望:25
帖 子:1830
专家分:30
注 册:2004-9-23
收藏
得分:0 

我说的那个就是 struct的名字。
一般我们定义struct的时候都是
struct code
{
string id;
……
}

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

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


成功会使人骄傲。如果你骄傲自大,你就会停止学习。不学习,人就停止了进步
2006-02-22 10:45
cf2000
Rank: 1
等 级:新手上路
帖 子:8
专家分:0
注 册:2006-2-22
收藏
得分:0 

你说的是这个结构的名称就是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的意思,我也不清楚。

2006-02-22 10:53
cf2000
Rank: 1
等 级:新手上路
帖 子:8
专家分:0
注 册:2006-2-22
收藏
得分:0 
这个结构里面本身包含了hid_configuration_descriptor这种数据类型,然后又定义了这样的一种结构,code是不是有特别的意思?
2006-02-22 10:56
柳儿
Rank: 6Rank: 6
等 级:贵宾
威 望:25
帖 子:1830
专家分:30
注 册:2004-9-23
收藏
得分:0 

code是不是自定义的数据类型?不过没见过这种用法。

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


成功会使人骄傲。如果你骄傲自大,你就会停止学习。不学习,人就停止了进步
2006-02-22 12:08
cf2000
Rank: 1
等 级:新手上路
帖 子:8
专家分:0
注 册:2006-2-22
收藏
得分:0 

恩,谢谢。这个东西本身是在头文件中的,我看这样吧,文件本身不大,我把它贴出来,你也能看的清楚点。

#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给搞糊涂了。

2006-02-22 12:38
柳儿
Rank: 6Rank: 6
等 级:贵宾
威 望:25
帖 子:1830
专家分:30
注 册:2004-9-23
收藏
得分:0 
楼主啊,这是源代码么?

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

成功会使人骄傲。如果你骄傲自大,你就会停止学习。不学习,人就停止了进步
2006-02-22 13:12
cf2000
Rank: 1
等 级:新手上路
帖 子:8
专家分:0
注 册:2006-2-22
收藏
得分:0 

恩,但是有一个是没有被注释的,你再看看那个HID设备类定义的那个。
不知道你是不是在单片机的c中见到过这种用法。象
code const BYTE String0Desc[STR0LEN] =
{
STR0LEN, 0x03, 0x09, 0x04
};
这种的话,不要code也能编译通过,但是就占用的data段多。不知道是不是这样做的话就把常量放在code段了?
但是定义结构的那个,去掉code的话编译就不能通过了。不知道什么意思。
谢谢你!~~

2006-02-22 13:23
快速回复:求助:程序中的code是什么意思?
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.015847 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved