• C

Problem with memcpy function

I get a compilation error with the following code>

C code:

char jobname[10];      
                  memcpy(jobname, "          ", 10);  /* this is line 131 */

Compilation errors:

GC99999/C(STATUS), 131.51: CZM0046(30) Syntax error.                      
GC99999/C(STATUS), 131.19: CZM0182(30) Arguments missing for built-in function __memcpy.                                                      
GC99999/C(STATUS), 131.19: CZM0277(30) Syntax error: possible missing ';' or ','?

I have used the same code in another program with no problem.
jc31415Asked:
Who is Participating?
 
Infinity08Commented:
Try this simple program :

----------
#include <stdlib.h>

int main(void) {
  char test[10];
  memcpy((void*) &test[0], (const void*) "test", (size_t) 5);
  memcpy(&test[0], "test", 5);
  memcpy(test, "test", 5);
  return 0;
}
----------

And see if, and at what line the compiler gives an error.

If it doesn't give an error at all, then check whether you correctly included the header file containing the declaration of memcpy(void*, const void*, size_t), AND that there's no re-declaration of memcpy anywhere !!!

If there is a compiler error at one of the above lines, then change your code to match the last correct line's syntax.

If the first line in the above code also provokes a compiler error, then you might want to check if the standard library hasn't been corrupted somehow. What compiler are you using ?
0
 
PaulCaswellCommented:
Hi jc31415,

Have you got:

#include <memory>

?

Paul
0
 
Harisha M GCommented:
Hi, it is not giving me any errors. Can you post some more code (before that line) ?

---
Harish
0
Firewall Management 201 with Professor Wool

In this whiteboard video, Professor Wool highlights the challenges, benefits and trade-offs of utilizing zero-touch automation for security policy change management. Watch and Learn!

 
Harisha M GCommented:
Paul, it works with

#include <string.h>

as well :)
0
 
Harisha M GCommented:
or.. the C++ <cstring>
0
 
PaulCaswellCommented:
Hi Harish,

Assuming there are no syntax errors prior to these lines I was guessing perhaps memcpy is undefined (lacking the header) but the undefined'edness would also be reported.

I'd guess 'memcpy' has been #defined incorrectly somewhere seems to me to be the next most likely option but it is distinctly rarer.

Lets see what JC has to say :-)

Paul
0
 
jc31415Author Commented:
Since I got the following error message the memcpy function is defined; it just says I have missing arguments.
       
GC99999/C(STATUS), 131.19: CZM0182(30) Arguments missing for built-in function __memcpy.

Also the next statement is:  
   
  memcpy(prtfil, (((var_record_t *)\
       lstptr2)->Data_Field),
       (((Qus_LSPL_Key_Info_t *)lstptr2)\
        ->Data_Length));  

and it doesn't get a compilation error.
0
 
cwwkieCommented:
if you comment out the line with the syntax error, does the compiler error disapear too?
0
 
jc31415Author Commented:
Actually when I recompiled after commenting out the line in error, the next reference to memcpy got the same error. When I commented out all references to memcpy I got no compilation errors.
0
 
PaulCaswellCommented:
Search for all references to 'memcpy' or '_memcpy' or '__memcpy' and see if any of them might specify the wrong number of parameters.

Paul
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.