ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
It has a C++ program that uses memset() and memcpy() which is giving me 'not in scope' errors. I have tried
Code:
#include <string> // original code - see below
and
#include <string.h> // more errors than <string>
and
#include <cstring> // same again
In /usr/include/string.h, memset() and memcpy() are declared:
Code:
__BEGIN_NAMESPACE_STD
/* Copy N bytes of SRC to DEST. */
extern void *memcpy (void *__restrict __dest, const void *__restrict __src,
size_t __n) __THROW __nonnull ((1, 2));
/* Copy N bytes of SRC to DEST, guaranteeing
correct behavior for overlapping strings. */
extern void *memmove (void *__dest, const void *__src, size_t __n)
__THROW __nonnull ((1, 2));
__END_NAMESPACE_STD
__BEGIN_NAMESPACE_STD
/* Set N bytes of S to C. */
extern void *memset (void *__s, int __c, size_t __n) __THROW __nonnull ((1));
Code snippets:
Code:
/*
This file is part of g15lcd.
g15lcd is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
...
*/
#include <iostream>
#include <cstdlib>
#include <usb.h>
#include <string>
#include <fstream>
#include <vector>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
...
void processInputLine(unsigned char *buffer, pthread_mutex_t *mutex, int *changed, string const &line)
{
if (line.length() < 3)
{
cout << "How about passing useful data into this program?" << endl;
return;
}
unsigned char buf[0x03e0];
memset(buf,0,0x03e0);
buf[0] = 0x03;
if (line[0] == 'T')
{
handleTextCommand(buf,line);
}
else if (line[0] == 'P')
{
handlePixelCommand(buf,line);
}
pthread_mutex_lock(mutex);
memcpy(buffer, buf, 0x03e0);
*changed = 1;
pthread_mutex_unlock(mutex);
}
Code:
$ make
g++ -O2 -Wall -pedantic -c font_8x8.cpp
g++ -O2 -Wall -pedantic -c font_7x5.cpp
g++ -O2 -Wall -pedantic -c font_6x4.cpp
g++ -O2 -Wall -pedantic -c lcd.cpp
lcd.cpp: In function ‘void processInputLine(unsigned char*, pthread_mutex_t*, int*, const string&)’:
lcd.cpp:234:23: error: ‘memset’ was not declared in this scope
memset(buf,0,0x03e0);
^
lcd.cpp:247:33: error: ‘memcpy’ was not declared in this scope
memcpy(buffer, buf, 0x03e0);
^
Makefile:18: recipe for target 'all' failed
make: *** [all] Error 1
In C++ I understand that functions can have a variable number of arguments as long as there are appropriate declarations, and that a 'not in scope' error is given if the wrong number of arguments is used. Is that the case here?
Off: I learned from experience that OP's aren't always reliable... for example, they tend not to give compiler-version-numbers, the complete source, the specification of the platform, etc
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.