打印
[AVR单片机]

iccavr 7.22版本下后插法建立单链表时编译不过

[复制链接]
1490|4
手机看帖
扫描二维码
随时随地手机跟帖
跳转到指定楼层
楼主
tongkunow|  楼主 | 2013-12-16 23:19 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
小弟想在iccavr 7.22版本下后插法建立单链表但是编译不通过
程序如下
#include <iom16v.h>
#include <macros.h>
#include <stdlib.h>
#include <stdio.h>

  typedef struct mac_id
{
   unsigned char id_num;
   unsigned char mac_addr[4];
  } mac_id_type;

  typedef struct node
{
   mac_id_type mi ;
   struct node * next ;
  }linklist ;
//用尾插法建立一个只有一个几点的单链表
void main(void)
{
        unsigned char j = 0;       
        unsigned char i = 0;
        unsigned char r = 0;
        unsigned char mstr_id_num = '0';
        unsigned char mstr_mac_num[4];
        unsigned char slave1_id_num = '1';
        unsigned char slave1_mac_num[4];
        unsigned char slave2_id_num = '2';
        unsigned char slave2_mac_num[4];
        linklist *l,*end,*nw;//链表的头指针L 尾指针end 新建节点指针new
        mac_id_type  macid; //mac_id_type结构体类型的变量
        mac_id_type * midp;// 指向mac_id_type结构体类型的指针
        macid.id_num = mstr_id_num;//macid变量的属性赋值
        l=NULL;// 链表的头指针L首先给个空地址
        end=l;// 链表的尾指针指向链表的头指针也为空
    mstr_mac_num[0]='0';
        mstr_mac_num[1]='0';
        mstr_mac_num[2]='0';
        mstr_mac_num[3]='0';
        slave1_mac_num[0]='0';
        slave1_mac_num[1]='0';
        slave1_mac_num[2]='0';
        slave1_mac_num[3]='1';
        slave2_mac_num[0]='0';
        slave2_mac_num[1]='0';
        slave2_mac_num[2]='0';
        slave2_mac_num[3]='2';
        for(i=0;i<4;i++)
        macid.mac_addr[i]=mstr_mac_num[i];//macid变量的属性赋值
        midp = & macid;//mac_id_type结构体类型的指针指向mac_id_type结构体类型的变量
    nw=(linklist *)malloc(sizeof(linklist));//分配一块linklist类型字节大小的存储空间 返回空间首地址给新建链表节点指针            
   nw.mi.id_num = midp.id_num;//新建链表节点的属性赋值
   for(r=0;r<4;r++)
   nw.mi.mac_addr[r]=midp.mac_addr[r];//新建链表节点的属性赋值
        if(!l) //如果头结点不存在
        l=nw;//则头指针指向新建节点
        else
        end.next=nw;//如果头结点已经存在,新建节点的地址给头节点的NEXT指针
        end=nw;//尾指针指向新建节点
        if(end)//如果链表不为空
        end.next=NULL;
}
在单独编译    nw=(linklist *)malloc(sizeof(linklist));时编译不通过
出现如下错误
!ERROR Function 'putchar' not defined. This is a hardware dependent

function,
  and it is not included in the ICCAVR default library. Please implement
  this function to match your target requirements. You can find examples
  of this function under the <install root>\examples.AVR directory. Make
  a copy of a suitable example, add it to your project and modify it if
  needed. The source code must #include the appropriate C header file
  (e.g. stdio.h) as it contains the special compiler pragma for 'putchar'.
!误差函数“的putchar”没有定义。这是一个依赖于硬件的功能,
  并且它不包含在ICCAVR默认库。请执行
  此功能以符合您的目标要求。你可以找到例子
  的<install ROOT>\ examples.AVR目录下此功能。使
  一个合适的例子的一个副本,把它添加到你的项目,如果修改
  需要的。源代码必须的#include相应的C头文件
  (如stdio.h中),因为它包含了特殊的编译器pragma对'的putchar“。

这句程序    nw=(linklist *)malloc(sizeof(linklist)); 是照着书上写的
真不知道哪里错了 就大神指点 万分感谢 感激不已

相关帖子

沙发
qin552011373| | 2013-12-18 08:18 | 只看该作者
你抄的那本书?

使用特权

评论回复
板凳
yushan210| | 2013-12-18 08:33 | 只看该作者
书是哪一年的书 和编译器的标准一样吗

使用特权

评论回复
地板
SLEET1986| | 2013-12-18 09:14 | 只看该作者
ERROR Function 'putchar' not defined. This is a hardware dependent

function,这个函数没定义,取决于你的硬件(单片机)examples.AVR目录里面有一些型号单片机的定义,可参考。

使用特权

评论回复
5
SLEET1986| | 2013-12-18 09:15 | 只看该作者
这句程序    nw=(linklist *)malloc(sizeof(linklist));没错,后面的程序很多错误,结构体指针要用->

使用特权

评论回复
发新帖 我要提问
您需要登录后才可以回帖 登录 | 注册

本版积分规则

2

主题

2

帖子

0

粉丝