473,396 Members | 1,743 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Why the simple code can not compile?

#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.

Thanks.

Sep 20 '07 #1
9 8703
Jack wrote:
#include "string.h"
#include <iostream>
using namespace std;
suppose the function is in some cxx file

void bzero(char*, size_t);
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.

Thanks.

--
Thanks
Barry
Sep 20 '07 #2
Jack 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.
man bzero (and check the include file).

--
Ian Collins.
Sep 20 '07 #3
On Sep 20, 11:25 am, Jack <junw2...@gmail.comwrote:
#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.

Of course I am assuming that you are talking about the bzero function
defined in the (c-standard) library. If you are talking about your
self-defined bzero function, make sure that its prototype is made
available.

Neelesh

-Neelesh
Sep 20 '07 #4
On Sep 20, 1:49 am, Neelesh Bodas <neelesh.bo...@gmail.comwrote:
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.

Of course I am assuming that you are talking about the bzero function
defined in the (c-standard) library. If you are talking about your
self-defined bzero function, make sure that its prototype is made
available.

There is no bzero in the standard C (or C++) library, but it's a
fairly common extension in *nix implementations.

Sep 20 '07 #5
On Sep 20, 8:49 am, Neelesh Bodas <neelesh.bo...@gmail.comwrote:
On Sep 20, 11:25 am, Jack <junw2...@gmail.comwrote:
#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'.
Only in certain versions of Unix, pre-1990.
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.
Not deprecated. It never officially existed, at least in
standard C. It was present in the Berkley distributions of
Unix, and is part of Posix, but in the supplementary header
<strings.h(not <string.h>). Given that it's deprecated by
Posix, however, and was never part of standard C, I'd definitely
replace it by memset (which is standard, and declared in
<string.h>---or you can use std::memset, and <cstring>).

--
James Kanze (GABI Software) email:ja*********@gmail.com
Conseils en informatique orientée objet/
Beratung in objektorientierter Datenverarbeitung
9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34

Sep 20 '07 #6
On Sep 19, 11:49 pm, Neelesh Bodas <neelesh.bo...@gmail.comwrote:
On Sep 20, 11:25 am, Jack <junw2...@gmail.comwrote:
#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.

Of course I am assuming that you are talking about the bzero function
defined in the (c-standard) library. If you are talking about your
self-defined bzero function, make sure that its prototype is made
available.

Neelesh

-Neelesh
Thanks. But it works fine on Linux when I used g++. And it is defined
in <string.hon Linux.

Sep 20 '07 #7

James Kanze wrote:

Not deprecated. It never officially existed, at least in
standard C. It was present in the Berkley distributions of
Unix, and is part of Posix, but in the supplementary header
<strings.h(not <string.h>). Given that it's deprecated by
Posix, however, and was never part of standard C, I'd definitely
replace it by memset (which is standard, and declared in
<string.h>---or you can use std::memset, and <cstring>).
Maybe I'm slightly paranoid, but I would rather use something
like this...

#include <cstddef>
#include <algorithm>

template <class T, std::size_t N>
void zero( T(&array)[N] )
{
std::fill( array, array+N, T() );
}

int main()
{
char array[] = "Hallo";
zero( array );
}

.... as I've seen memset being used erroneously by mistake
one to many times. OTOH I think you would probably too.

Regards,

Werner

Sep 20 '07 #8
On Sep 20, 6:34 pm, werasm <wer...@gmail.comwrote:
James Kanze wrote:
Not deprecated. It never officially existed, at least in
standard C. It was present in the Berkley distributions of
Unix, and is part of Posix, but in the supplementary header
<strings.h(not <string.h>). Given that it's deprecated by
Posix, however, and was never part of standard C, I'd definitely
replace it by memset (which is standard, and declared in
<string.h>---or you can use std::memset, and <cstring>).
Maybe I'm slightly paranoid, but I would rather use something
like this...
Not paranoid, just good programming practice.
#include <cstddef>
#include <algorithm>
template <class T, std::size_t N>
void zero( T(&array)[N] )
{
std::fill( array, array+N, T() );
}
int main()
{
char array[] = "Hallo";
zero( array );
}
... as I've seen memset being used erroneously by mistake
one to many times. OTOH I think you would probably too.
Now that you mention it, yes. Memset only works for C style
arrays of integers. std::fill (and std::fill_n) works for
everything. (And in C, it was a common error to see memset used
for arrays of double or of pointer.)

--
James Kanze (GABI Software) email:ja*********@gmail.com
Conseils en informatique orientée objet/
Beratung in objektorientierter Datenverarbeitung
9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34

Sep 21 '07 #9
In article <11**********************@22g2000hsm.googlegroups. com>,
ja*********@gmail.com says...

[ ... ]
Now that you mention it, yes. Memset only works for C style
arrays of integers.
It works for arrays of char. For arrays of integers, it works only for a
rather loose definition of "works". Generally speaking, the only value
that's useful for non-char types is zero. For example:

int x;

memset(&x, 1, sizeof(x));

std::cout << x;

One likely result:

16843009

--
Later,
Jerry.

The universe is a figment of its own imagination.
Sep 21 '07 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: BigMan | last post by:
Should the following piece of code compile or not according the C++ standard? Why? class t { public: t( ) { } t( t& a ) { } template< typename ttt >
2
by: Brad Pepers | last post by:
For the life of me I can't see why this code won't compile even though its very simple. Any hints? I get errors in NumberValcon::format(int) when it tries to call format() but why doesn't it use...
13
by: tindog | last post by:
I am brand new to this programming especially C#. I am confused (at the moment). I have bought two books to get started to learn C# language and Visual C#.net 2003 in 24 hours. Which is the best to...
5
by: Laurent Allardin | last post by:
Hi, Why this code compile??? We should not be able to Override the code by using the Overloads since the sub as exactly the same parameters.... Thank you. Laurent Allardin,MCSD,MCAD
18
by: Roy | last post by:
using Team Studio 2005 1. Create a new web site 2. Add a new class to the project 3. In the Page_Load handler of default.aspx.cxs, create a reference to the new class 4. compile solution...
10
by: Harsh_forC | last post by:
hello folks, here i m inserting d very simple code tat im trying to execute.. but still gettin d same error msg,.." Not enuf memory" #include<stdlib.h> #include<stdio.h> void main(void) {
4
by: VB Programmer | last post by:
In 1.1 if I made a simple code change I would just copy the dll in the bin folder to the website and that's it. If I make a simple code change in 2.0 what file(s) would I need to copy to the web...
10
by: Sourcerer | last post by:
I wrote this very simple code in .NET VC++. I compiled it on my system, and tried to run it on my friend's computer (he doesn't have the compiler). We both have Windows XP Professional. I have .NET...
30
by: galiorenye | last post by:
Hi, Given this code: A** ppA = new A*; A *pA = NULL; for(int i = 0; i < 10; ++i) { pA = ppA; //do something with pA
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.