Click here to Skip to main content
15,913,231 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
QuestionRe: zero-sized array in struct/union Pin
Richard MacCutchan5-Aug-19 22:14
mveRichard MacCutchan5-Aug-19 22:14 
AnswerRe: zero-sized array in struct/union Pin
_Flaviu5-Aug-19 22:27
_Flaviu5-Aug-19 22:27 
GeneralRe: zero-sized array in struct/union Pin
Richard MacCutchan5-Aug-19 22:43
mveRichard MacCutchan5-Aug-19 22:43 
GeneralRe: zero-sized array in struct/union Pin
Stefan_Lang6-Aug-19 21:53
Stefan_Lang6-Aug-19 21:53 
GeneralRe: zero-sized array in struct/union Pin
Richard MacCutchan7-Aug-19 1:27
mveRichard MacCutchan7-Aug-19 1:27 
GeneralGet rid of the [] Pin
Davie212406-Aug-19 10:19
Davie212406-Aug-19 10:19 
AnswerRe: zero-sized array in struct/union Pin
CPallini5-Aug-19 22:32
mveCPallini5-Aug-19 22:32 
GeneralRe: zero-sized array in struct/union Pin
_Flaviu5-Aug-19 22:41
_Flaviu5-Aug-19 22:41 
SuggestionRe: zero-sized array in struct/union Pin
Richard MacCutchan5-Aug-19 22:44
mveRichard MacCutchan5-Aug-19 22:44 
GeneralRe: zero-sized array in struct/union Pin
Stefan_Lang6-Aug-19 21:58
Stefan_Lang6-Aug-19 21:58 
GeneralRe: zero-sized array in struct/union Pin
_Flaviu5-Aug-19 22:53
_Flaviu5-Aug-19 22:53 
Questionerror C2143 error C2059 Pin
_Flaviu31-Jul-19 1:03
_Flaviu31-Jul-19 1:03 
QuestionRe: error C2143 error C2059 Pin
Richard MacCutchan31-Jul-19 2:01
mveRichard MacCutchan31-Jul-19 2:01 
AnswerRe: error C2143 error C2059 Pin
_Flaviu31-Jul-19 2:38
_Flaviu31-Jul-19 2:38 
GeneralRe: error C2143 error C2059 Pin
Richard MacCutchan31-Jul-19 2:54
mveRichard MacCutchan31-Jul-19 2:54 
GeneralRe: error C2143 error C2059 Pin
_Flaviu31-Jul-19 3:27
_Flaviu31-Jul-19 3:27 
GeneralRe: error C2143 error C2059 Pin
Richard MacCutchan31-Jul-19 4:03
mveRichard MacCutchan31-Jul-19 4:03 
GeneralRe: error C2143 error C2059 Pin
_Flaviu31-Jul-19 22:01
_Flaviu31-Jul-19 22:01 
GeneralRe: error C2143 error C2059 Pin
k505431-Jul-19 5:39
mvek505431-Jul-19 5:39 
GeneralRe: error C2143 error C2059 Pin
_Flaviu31-Jul-19 21:06
_Flaviu31-Jul-19 21:06 
QuestionRe: error C2143 error C2059 Pin
David Crow1-Aug-19 3:22
David Crow1-Aug-19 3:22 
AnswerRe: error C2143 error C2059 Pin
k50541-Aug-19 4:28
mvek50541-Aug-19 4:28 
GeneralRe: error C2143 error C2059 Pin
k50541-Aug-19 3:57
mvek50541-Aug-19 3:57 
The only way I know is to compare member by member:
C
struct foo {
   short s;
   double d;
   char str[24];
};

int compare_foo(const struct foo *f1, const struct foo *f2)
{
    int retval;

    if( (retval =  f1->s - f2->s) != 0)
        return retval;

    if( (retval = f1->d - f2->d) != 0)
         return retval;

    return strcmp(f1->str, f2->str);
}
Note that this demonstrates another reason that you should avoid memcmp() on structs: if the struct in question contains strings, the portions of the string after the terminating null byte may not be equal, so strcmp(str1,str2) might not return the same value as memcmp(str1, str2, sizeof str1). You could, use memcmp(str1, str2, strlen(s1)+1): the extra byte accounting for the terminating null byte, so that you do not get a false equal on e.g. "help" and "helper". But that's a silly way to compare strings: you effectively run through str1 twice, once to get its length, then again to do the comparison, assuming str1 is equal to, or an initial substring of, str2. Use strcmp() to compare strings, or strcasecmp() or strcoll() when appropriate.

modified 1-Aug-19 10:35am.

GeneralRe: error C2143 error C2059 Pin
Richard MacCutchan31-Jul-19 21:32
mveRichard MacCutchan31-Jul-19 21:32 
GeneralRe: error C2143 error C2059 Pin
Peter_in_27801-Aug-19 0:53
professionalPeter_in_27801-Aug-19 0:53 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.