memcmp Questions
9
Solved
I'm trying to see if a struct came back as all 0xFF for the size of the struct.
memcmp seems like the obvious starting point, BUT I'd have to allocate a second memory block, populate it with 0xFF'...
7
Solved
Precondition: Consider such a class or struct T, that for two objects a and b of type T
memcmp(&a, &b, sizeof(T)) == 0
yields the same result as
a.member1 == b.member1 && a.memb...
Ascender asked 4/3, 2015 at 15:31
1
I really like std::byte as a distinct type that implements the concept of byte as specified in the C++ language definition. What I don't like is the fact that modern C++ compilers will produce less...
3
Solved
Motivated by this question, I compared three different functions for checking if 8 bytes pointed to by the argument are zeros (note that in the original question, characters are compared with '0', ...
Charades asked 13/8, 2020 at 9:55
2
Solved
In particular, is the following well-defined, or does it exhibit undefined behavior?
memcmp(0, 0, 0);
Does this differ between C and C++? Ideally, please provide a quote from the standard(s).
6
Solved
I want to compare structs in a generic way and I've done something like this (I cannot share the actual source, so ask for more details if necessary):
template<typename Data>
bool structCmp...
2
I am working on some low level code with high level interfaces and felt need for comparisons operator for unit testing for plain old data types(like FILETIME struct) but since C++ doesn't even prov...
Bluebeard asked 3/6, 2018 at 13:41
6
Solved
2
Solved
I have compared two string literals using the memcmp function.
#include <stdio.h>
#include <string.h>
int main()
{
char str1[] = "abcd";
char str2[] = "ab";
if (memcmp(str1, str...
Levity asked 2/5, 2018 at 7:17
1
Solved
Consider:
constexpr char s1[] = "a";
constexpr char s2[] = "abc";
std::memcmp(s1, s2, 3);
If memcmp stops at the first difference it sees, it will not read past the second byte...
4
Solved
How can I do reverse memory comparison? As in, I give the ends of two sequences and I want the pointer to be decremented towards the beginning, not incremented towards the end.
5
Solved
Is the defacto method for comparing arrays (in C) to use memcmp from string.h?
I want to compare arrays of ints and doubles in my unit tests
I am unsure whether to use something like:
double a[]...
Melodics asked 6/12, 2011 at 12:32
1
Solved
A naive implementation of memcmp() goes something like this (from this answer):
int memcmp_test(const char *cs_in, const char *ct_in, size_t n)
{
size_t i;
const unsigned char * cs = (const uns...
Adlib asked 8/4, 2014 at 11:21
3
Solved
Why is memcmp(a, b, size) so much faster than:
for(i = 0; i < nelements; i++) {
if a[i] != b[i] return 0;
}
return 1;
Is memcmp a CPU instruction or something? It must be pretty deep because...
Emulous asked 14/1, 2014 at 5:42
1
Solved
In reading: How can I check that elements of an array are all same without using counter? , @Skizz uses the nifty solution:
memcmp (&string [0], &string [1], sizeof string [0] * (N - 1))
...
6
Solved
I need to compare a block of memory to a fixed value in C. Can I do this with memcmp? Something like:
memcmp (starting_address , fixed_value , num_byte)
I need fixed_value to be a fixed value not...
5
Solved
If I have two C structures initialised to have identical members, can I guarantee that:
memcmp(&struct1, &struct2, sizeof(my_struct))
will always return zero?
2
Solved
There is a well-known efficiency for comparing two byte-arrays in .Net by importing the memcmp function from msvcrt.dll, as described here.
Is there an equivalent library import in mono? Would it ...
8
The following is the Microsoft CRT implementation of memcmp:
int memcmp(const void* buf1,
const void* buf2,
size_t count)
{
if(!count)
return(0);
while(--count && *(char*)buf1 == *(c...
2
Solved
This is a bit puzzling here. The following code is part of a little testing application to verify that code changes didn't introduce a regression. To make it fast we used memcmp which appears to be...
3
I am trying to write code to compare two string.
In windows i can use strcmp but i want write for multibyte character string so that it compatible to all other platform
Can i use memcmp?
if no then...
3
Solved
How to check whether or not C++ type is trivially copyable? I have a class, which uses memcpy and memcmp functions with specified template type T and I would like to fire assert for types, that are...
Egon asked 14/2, 2011 at 16:11
6
Solved
After seeing this question, my first thought was that it'd be trivial to define generic equivalence and relational operators:
#include <cstring>
template<class T>
bool operator==(cons...
Armidaarmiger asked 31/8, 2010 at 14:38
4
Solved
I am working on fixing older code for my job. It is currently written in C++. They converted static allocation to dynamic but didn't edit the memsets/memcmp/memcpy. This is my first programming int...
1
© 2022 - 2024 — McMap. All rights reserved.