首页 新闻 会员 周边

C++ 提示:../main.c:26: error: expected primary-expression before '.' token

0
悬赏园豆:20 [已解决问题] 解决于 2011-08-22 19:30
#include <avr/io.h>
#include <stdio.h>
#include <avr/interrupt.h>  
static FILE mystdout = FDEV_SETUP_STREAM(uart_putchar, NULL,_FDEV_SETUP_WRITE);
static FILE mystdin = FDEV_SETUP_STREAM(NULL,uart_getchar, _FDEV_SETUP_READ);  
stdout = &mystdout;stdin = &mystdin;

基于Eclipse+ WINAVR 平台的  C++ 编译提示

描述 资源 路径 位置 类型
expected primary-expression before '.' token main.cpp ArduinoTemplte 51 C/C++ Problem

请问这是什么情况,该怎么解决呢?

我想在 atmega1280 串口使用 scanf 和printf 函数,一编译就出现这种错误,我用 avr-gcc.exe 编译可以通过,可是我想用 avr-c++.exe 编译,就出现上面的问题。小弟至学过C,没学过c++,请问大侠们,这该怎么解决呢?诚恳请赐教.....

问题补充:
用avr-gcc编译是可以通过的,但用avr-c++就出现上面错误。
点击错误信息,错误指向下面这两句
static FILE mystdout = FDEV_SETUP_STREAM(uart_putchar, NULL,_FDEV_SETUP_WRITE);
static FILE mystdin = FDEV_SETUP_STREAM(NULL,uart_getchar, _FDEV_SETUP_READ);
宏展开如下
在stdio.h中
#define FILE struct __file
struct __file {
char *buf; /* buffer pointer */
unsigned
char unget; /* ungetc() buffer */
uint8_t flags;
/* flags, see below */
#define __SRD 0x0001 /* OK to read */
#define __SWR 0x0002 /* OK to write */
#define __SSTR 0x0004 /* this is an sprintf/snprintf string */
#define __SPGM 0x0008 /* fmt string is in progmem */
#define __SERR 0x0010 /* found error */
#define __SEOF 0x0020 /* found EOF */
#define __SUNGET 0x040 /* ungetc() happened */
#define __SMALLOC 0x80 /* handle is malloc()ed */
#if 0
/* possible future extensions, will require uint16_t flags */
#define __SRW 0x0100 /* open for reading & writing */
#define __SLBF 0x0200 /* line buffered */
#define __SNBF 0x0400 /* unbuffered */
#define __SMBF 0x0800 /* buf is from malloc */
#endif
int size; /* size of buffer */
int len; /* characters read or written so far */
int (*put)(char, struct __file *); /* function to write one char to device */
int (*get)(struct __file *); /* function to read one char from device */
void *udata; /* User defined and accessible data. */
};

#if defined(__DOXYGEN__)
/**
\brief Initializer for a user-supplied stdio stream

This macro acts similar to fdev_setup_stream(), but it is to be
used as the initializer of a variable of type FILE.

The remaining arguments are to be used as explained in
fdev_setup_stream().
*/
#define FDEV_SETUP_STREAM(put, get, rwflag)
#else /* !DOXYGEN */
#define FDEV_SETUP_STREAM(p, g, f) \
{ \
.put
= p, \
.
get = g, \
.flags
= f, \
.udata
= 0, \
}
Mr.Shan的主页 Mr.Shan | 初学一级 | 园豆:180
提问于:2011-08-19 22:46
< >
分享
最佳答案
0

输出到标准输出流stdout,从标准流stdin输入。 应用时要为输出输入流指定设备,有两种方法: 第一种通过FDEV_SETUP_STREAM宏来定义流: (C编译器)static FILE mystdout = FDEV_SETUP_STREAM(dev_putchar, NULL,_FDEV_SETUP_WRITE); ststatic FILE mystdin = FDEV_SETUP_STREAM(NULL,dev_getchar, _FDEV_SETUP_READ); stdout=&mystdout;stdin=&mystdin; dev_putchar,dev_getchar分别是负责向设备输出、输入一个字符的函数 原型int dev_putchar(charc,FILE *stream),int dev_get(FILE *stream))。  第二种通过fdevopen()函数指定 (C++编译器)fdevopen()函数原型:FILE *fdevopen(int(*put)(char c,FILE *stream),int(*get)(FILE *stream)) 第一个参数指向设备输出函数,第二个参数指向设备输入函数,返回流指针。 第一个参数为NULL,则流按只读方式打开,stdin是流的引用名。 第二个参数为NULL,则流按只写方式打开,stdout是流的引用名。 两个参数不为NULL,则流按读写方式打开,stdout,stdin都是流的引用名。 stdout=mystdout;stdin=mystdin; 

FDEV_SETUP_STREAM() uses some features that are only available in C99 but not in C++ (initialization of named struct members). So for C++, you have to resort to use either fdevopen(), or fdev_setup_stream().

收获园豆:20
jukeshang | 菜鸟二级 |园豆:230 | 2011-08-20 16:03
感激不尽!
Mr.Shan | 园豆:180 (初学一级) | 2011-08-22 19:29
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册