LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 03-05-2015, 03:44 AM   #1
CollieJim
Member
 
Registered: Mar 2005
Distribution: Gentoo, Kubuntu
Posts: 582

Rep: Reputation: 28
Where is memset()


I'm compiling software to support my Logitech G510s keyboard. It is obtained from
http://sourceforge.net/projects/g15daemon/

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?
 
Old 03-05-2015, 03:49 AM   #2
NevemTeve
Senior Member
 
Registered: Oct 2011
Location: Budapest
Distribution: Debian/GNU/Linux, AIX
Posts: 4,856
Blog Entries: 1

Rep: Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869
Do these steps:

1. 'man memcpy' -> you find out it is in <string.h>
2. beacuse it is C++, change it to <cstring>
3. so put this into your code:
Code:
#include <cstring>
Edit: my g++ version is: g++ (Debian 4.4.5-8) 4.4.5

Last edited by NevemTeve; 03-05-2015 at 03:54 AM.
 
Old 03-05-2015, 04:13 AM   #3
veerain
Senior Member
 
Registered: Mar 2005
Location: Earth bound to Helios
Distribution: Custom
Posts: 2,524

Rep: Reputation: 319Reputation: 319Reputation: 319Reputation: 319
Quote:
Originally Posted by NevemTeve View Post
Do these steps:

1. 'man memcpy' -> you find out it is in <string.h>
2. beacuse it is C++, change it to <cstring>
3. so put this into your code:
Code:
#include <cstring>
Edit: my g++ version is: g++ (Debian 4.4.5-8) 4.4.5
But OP says he has tried this already.
 
1 members found this post helpful.
Old 03-05-2015, 04:23 AM   #4
NevemTeve
Senior Member
 
Registered: Oct 2011
Location: Budapest
Distribution: Debian/GNU/Linux, AIX
Posts: 4,856
Blog Entries: 1

Rep: Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869
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
 
1 members found this post helpful.
Old 03-05-2015, 04:58 AM   #5
CollieJim
Member
 
Registered: Mar 2005
Distribution: Gentoo, Kubuntu
Posts: 582

Original Poster
Rep: Reputation: 28
Unreliable is right! When I initially substituted cstring I failed to notice that the larger batch of errors I got was for a different file...

It also needed cstring, and all is well now.

Thanks for the help.

Last edited by CollieJim; 03-05-2015 at 05:00 AM.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] error: 'memset' in not declared in this scope isaacjun16 Ubuntu 3 10-01-2010 04:22 PM
time taken by memset SlevinKelvera Linux - Embedded & Single-board computer 0 08-10-2009 08:05 AM
using memset() functions for graphics gvp87 Programming 2 02-05-2008 05:10 PM
graphic function with memset() gvp87 Programming 1 01-31-2008 12:04 AM
memset vs char arr initialization syseeker Programming 4 03-29-2006 09:01 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 05:24 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration