Skip to content

Instantly share code, notes, and snippets.

@DBJDBJ
Created August 7, 2021 15:47
Show Gist options
  • Save DBJDBJ/23b3aef0c3bbb252e870c964a9794cd8 to your computer and use it in GitHub Desktop.
Save DBJDBJ/23b3aef0c3bbb252e870c964a9794cd8 to your computer and use it in GitHub Desktop.
DBJ ISO C STRING COMPARE
// ----------------------------------------------
// (c) 2021 by dbj@dbj.org
// https://dbj.org/license_dbj
// https://godbolt.org/z/vaMMrvM85
// ----------------------------------------------
#include <assert.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdbool.h>
#if __STDC_VERSION__ < 199901L
#error Please use C99 or better
#endif
// ----------------------------------------------
#define P(F, X) printf("\n%4d: %32s: " F, __LINE__, #X, (X))
// ----------------------------------------------
bool dbj_strcmp(const int N, const int M, const char L[static N],
const char R[static M])
{
if (N == M)
return ! strcmp(L, R);
return false ;
}
static int test_dbj_strcmp(
char const ASTR[static 1], char const BSTR[static 1]) {
return dbj_strcmp(
strlen(ASTR),
strlen(BSTR), ASTR, BSTR
);
}
//////////////////////////////////////////////////
///
int main(void) {
P("%d", test_dbj_strcmp("A", "VVV"));
P("%d", test_dbj_strcmp("A", "A"));
P("%d", test_dbj_strcmp("V", "A"));
return EXIT_SUCCESS;
}
@DBJDBJ
Copy link
Author

DBJDBJ commented Aug 7, 2021

I am sure you can package this as a stand-alone executable. Just please respect the license.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment