Re: Why the simple code can not compile?
On Sep 20, 6:17 pm, Jack <junw2...@gmail.com> wrote:
On Sep 19, 11:49 pm, Neelesh Bodas <neelesh.bo...@gmail.com> wrote:
On Sep 20, 11:25 am, Jack <junw2...@gmail.com> wrote:
#include "string.h"
#include <iostream>
using namespace std;
int main()
{
char buf[1024] = "This is a test.";
int len = 1024;
bzero(buf, len);
cout<<"buf::"<<buf<<endl;
}
The error is:
line 8: Error: The function "bzero" must have a prototype.
1 Error(s) detected.
I tried to compile it on Solaris SUN.
bzero was declared in C header 'strings.h'. I am not sure if C++
header strings.h declares it, but othe point to note is that this
function is deprecated, and it is suggested (by 'man bzero') that
memset be used instead.
[...]
Thanks. But it works fine on Linux when I used g++. And it is
defined in <string.h> on Linux.
Which is an error. Neither C nor Posix allow <string.h> to
contain the symbol bzero in any form; according to the
standards, the following program should compile and run
everywhere, both as C and as C++:
#define bzero "Hello, World!"
#include <string.h>
#include <stdio.h>
int
main()
{
printf( "%s\n", bzero ) ;
return 0 ;
}
(Curiously, on my Linux, it compiles as C, but not as C++. So
presumably, there are some #ifdef's somewhere which mean that
the symbol is not defined if you invoke the standard compliant C
compiler. And that something isn't being defined correctly when
you invoke the standard compliant C++ compiler; a bug report is
probably in order.)
--
James Kanze (GABI Software) email:james.kanze@gmail.com
Conseils en informatique orient=E9e objet/
Beratung in objektorientierter Datenverarbeitung
9 place S=E9mard, 78210 St.-Cyr-l'=C9cole, France, +33 (0)1 30 23 00 34