Click here to Skip to main content
15,886,689 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: Visual Studio error LNK2005: variable XXX redefined in xxx.obj Pin
Richard MacCutchan29-Nov-15 22:22
mveRichard MacCutchan29-Nov-15 22:22 
GeneralRe: Visual Studio error LNK2005: variable XXX redefined in xxx.obj Pin
«_Superman_»29-Nov-15 23:07
professional«_Superman_»29-Nov-15 23:07 
GeneralRe: Visual Studio error LNK2005: variable XXX redefined in xxx.obj Pin
Richard MacCutchan29-Nov-15 23:38
mveRichard MacCutchan29-Nov-15 23:38 
GeneralRe: Visual Studio error LNK2005: variable XXX redefined in xxx.obj Pin
«_Superman_»29-Nov-15 23:40
professional«_Superman_»29-Nov-15 23:40 
GeneralRe: Visual Studio error LNK2005: variable XXX redefined in xxx.obj Pin
Richard MacCutchan30-Nov-15 0:01
mveRichard MacCutchan30-Nov-15 0:01 
Questionc langugae Pin
ravi siriki23-Nov-15 1:58
ravi siriki23-Nov-15 1:58 
AnswerRe: c langugae Pin
David Crow23-Nov-15 2:38
David Crow23-Nov-15 2:38 
QuestionQuestion about malloc a struct Pin
Millenia Nova20-Nov-15 16:02
Millenia Nova20-Nov-15 16:02 
The code below uses a variable's type as size in malloc(). And I printf the size of //line 1, b and c to find out their sizes malloc will allocation the space for them in heap.

Question part 1:
One person told me I should use // line a's size to malloc in // #####, while the other person said I should use //line c instead. They do have the same size in printf(). Which one is correct? Why?

Question part 2:
// line b and // line c both have the same type of variable pointers, but why do they have different sizes?

struct Vector {
double *data;
size_t size;
};

int main()
{ int a, b, d;
int sz = 12;

a = sizeof(struct Vector); // line a
printf("%d\n", a); //a = 16

b = sizeof(struct Vector*); // line b
printf("%d\n", b); //b = 8

c = sizeof(*retVal); // line c
printf("%d\n\n", c); //c = 16

struct Vector *retVal = malloc (sizeof (struct Vector)); //#####
retVal->data = malloc (sz * sizeof (double));

// Set size and return.
retVal->size = sz;
printf("retVal->size: %d\n", sz);

return 0;
}

Thank you for your help. Smile | :)
AnswerRe: Question about malloc a struct Pin
Jochen Arndt20-Nov-15 21:45
professionalJochen Arndt20-Nov-15 21:45 
GeneralRe: Question about malloc a struct Pin
Millenia Nova21-Nov-15 21:53
Millenia Nova21-Nov-15 21:53 
GeneralRe: Question about malloc a struct Pin
Jochen Arndt22-Nov-15 0:22
professionalJochen Arndt22-Nov-15 0:22 
PraiseRe: Question about malloc a struct Pin
Millenia Nova22-Nov-15 11:12
Millenia Nova22-Nov-15 11:12 
AnswerRe: Question about malloc a struct Pin
Richard MacCutchan20-Nov-15 21:45
mveRichard MacCutchan20-Nov-15 21:45 
QuestionMFC Printing of multiple views for a single doc Pin
cc.caprani20-Nov-15 2:51
cc.caprani20-Nov-15 2:51 
Question. Pin
Brisingr Aerowing19-Nov-15 18:11
professionalBrisingr Aerowing19-Nov-15 18:11 
AnswerRe: Trying to port libcddb to MSVC, having issues... Pin
Jochen Arndt19-Nov-15 21:05
professionalJochen Arndt19-Nov-15 21:05 
QuestionRe: Trying to port libcddb to MSVC, having issues... Pin
CPallini19-Nov-15 21:24
mveCPallini19-Nov-15 21:24 
AnswerRe: Trying to port libcddb to MSVC, having issues... Pin
Richard MacCutchan19-Nov-15 23:13
mveRichard MacCutchan19-Nov-15 23:13 
GeneralRe: Trying to port libcddb to MSVC, having issues... Pin
Jochen Arndt20-Nov-15 0:14
professionalJochen Arndt20-Nov-15 0:14 
GeneralRe: Trying to port libcddb to MSVC, having issues... Pin
Richard MacCutchan20-Nov-15 0:23
mveRichard MacCutchan20-Nov-15 0:23 
GeneralRe: Trying to port libcddb to MSVC, having issues... Pin
Jochen Arndt20-Nov-15 0:53
professionalJochen Arndt20-Nov-15 0:53 
GeneralRe: Trying to port libcddb to MSVC, having issues... Pin
Richard MacCutchan20-Nov-15 3:02
mveRichard MacCutchan20-Nov-15 3:02 
GeneralRe: Trying to port libcddb to MSVC, having issues... Pin
Jochen Arndt20-Nov-15 3:06
professionalJochen Arndt20-Nov-15 3:06 
GeneralRe: Trying to port libcddb to MSVC, having issues... Pin
Richard MacCutchan20-Nov-15 3:03
mveRichard MacCutchan20-Nov-15 3:03 
QuestionSTL list member function(S) Pin
Amr.Mohammad8719-Nov-15 7:05
Amr.Mohammad8719-Nov-15 7:05 

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.