strcmp - c++ best way to compare byte array to struct -


I need help I have a unsigned char * and say I have a straight

  struct {int a = 3; Four b = 'd'; Double c = 3.14; Four d = 'e'; } Cmp; Unsigned char input [1000]; L = RQV (sockfd, input, psychof (CMP), 0);  

I have to compare CFP and input. What is the fastest way?

Thank you very much earlier.

If the compiler guarantees that there is no interval between fields in the structure (usually due to packing ) Or you can use #pragna to cancel any such interval, you can either:

  memcmp (& amp; cmp, input, size (steak thaestrat ));  

Or, my favorite:

  CMP == * (Structure TheStruct *) input //  

but Depending on the field, it would be a more secure way to compare on one area. Also, prepare special functions to remove the ingots, floats, etc. From raw input, for example, to remove an int on index N

  * (int *) and simple as input [n]  

But it may be more complex, such as 8, 16, shifting of cherry on 24 bits.

In essence, communication data should be done in the most robust manner to reach, checking every basic element and not believing anything.


Comments

Popular posts from this blog

import - Python ImportError: No module named wmi -

Editing Python Class in Shell and SQLAlchemy -

c# - MySQL Parameterized Select Query joining tables issue -