Click here to Skip to main content
14,926,387 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
QuestionC++ programming Pin
TanyaRaunak15-May-21 2:51
MemberTanyaRaunak15-May-21 2:51 
AnswerRe: C++ programming Pin
Victor Nijegorodov15-May-21 3:50
MemberVictor Nijegorodov15-May-21 3:50 
AnswerRe: C++ programming Pin
Richard MacCutchan15-May-21 6:15
mveRichard MacCutchan15-May-21 6:15 
QuestionMessage Closed Pin
15-May-21 1:38
MemberJimieSitu15-May-21 1:38 
AnswerRe: cross platform dynamic dll Pin
Richard MacCutchan14-May-21 22:21
mveRichard MacCutchan14-May-21 22:21 
GeneralRe: cross platform dynamic dll Pin
Richard Deeming18-May-21 3:24
mveRichard Deeming18-May-21 3:24 
QuestionC++ Structure layouts - how to determine padding and what not - VS2008 but it's a general question Pin
charlieg14-May-21 11:01
Membercharlieg14-May-21 11:01 
AnswerRe: C++ Structure layouts - how to determine padding and what not - VS2008 but it's a general question Pin
k505414-May-21 12:02
mvek505414-May-21 12:02 
I'm not sure why you'd be having data overruns, assuming you're sizing any I/O or copying correctly. Even if you have an "anonymous" buffer (e.g. char *), that you're copying your struct from, things should still work correctly with the appropriate sizeof operator in use.
I don't know of any tool within VS that will give you the information you need, but you might get some mileage out of [pack pragma | Microsoft Docs](https://docs.microsoft.com/en-us/cpp/preprocessor/pack?view=msvc-160), and or [offsetof Macro | Microsoft Docs](https://docs.microsoft.com/en-us/cpp/c-runtime-library/reference/offsetof-macro?view=msvc-160). Either or both won't save you from some typing though.
I think you need to be careful with #pragma pack. X86-64 doesn't seem to have a problem accessing unaligned data, but I assume its slower to do so than correctly aligned data. Other architectures though are not as accommodating. For example, the following code works fine on X86-64 in both 64 bit and 32 bit modes (at least using linux), but gets a bus error when running under arm-32
C
#include <stdio.h>
#include <stdlib.h>

int main()
{
    void *ptr = malloc(1024);
    char *tmp = ptr;

    for(size_t i = 0; i < 24; i++, ++tmp) {
        long double *d = (long double *)tmp;
        *d = i * 2.0L;
        printf("tmp = %p, d = %p *d = %Lf\n", tmp, d, *d);
    }

    free(ptr);

    return 0;
}
Keep Calm and Carry On

GeneralRe: C++ Structure layouts - how to determine padding and what not - VS2008 but it's a general question Pin
harold aptroot14-May-21 18:58
Memberharold aptroot14-May-21 18:58 
GeneralRe: C++ Structure layouts - how to determine padding and what not - VS2008 but it's a general question Pin
charlieg16-May-21 3:46
Membercharlieg16-May-21 3:46 
GeneralRe: C++ Structure layouts - how to determine padding and what not - VS2008 but it's a general question Pin
k505416-May-21 4:51
mvek505416-May-21 4:51 
GeneralRe: C++ Structure layouts - how to determine padding and what not - VS2008 but it's a general question Pin
charlieg16-May-21 6:05
Membercharlieg16-May-21 6:05 
GeneralRe: C++ Structure layouts - how to determine padding and what not - VS2008 but it's a general question Pin
Richard MacCutchan16-May-21 21:21
mveRichard MacCutchan16-May-21 21:21 
GeneralRe: C++ Structure layouts - how to determine padding and what not - VS2008 but it's a general question Pin
charlieg17-May-21 1:37
Membercharlieg17-May-21 1:37 
GeneralRe: C++ Structure layouts - how to determine padding and what not - VS2008 but it's a general question Pin
Bram van Kampen10-Jun-21 14:33
MemberBram van Kampen10-Jun-21 14:33 
AnswerRe: C++ Structure layouts - how to determine padding and what not - VS2008 but it's a general question Pin
Richard MacCutchan14-May-21 22:19
mveRichard MacCutchan14-May-21 22:19 
AnswerRe: C++ Structure layouts - how to determine padding and what not - VS2008 but it's a general question Pin
charlieg16-May-21 1:57
Membercharlieg16-May-21 1:57 
QuestionHow to migrate qt creator project (that doesn't need qt) to visual studio Pin
PristoMiky12-May-21 2:50
MemberPristoMiky12-May-21 2:50 
AnswerRe: How to migrate qt creator project (that doesn't need qt) to visual studio Pin
_Flaviu12-May-21 23:03
Member_Flaviu12-May-21 23:03 
GeneralRe: How to migrate qt creator project (that doesn't need qt) to visual studio Pin
Maximilien13-May-21 7:08
MemberMaximilien13-May-21 7:08 
AnswerRe: How to migrate qt creator project (that doesn't need qt) to visual studio Pin
Richard MacCutchan13-May-21 0:11
mveRichard MacCutchan13-May-21 0:11 
QuestionQuestion Arduino programming + joystick + bulbs Pin
titi titi11-May-21 12:55
Membertiti titi11-May-21 12:55 
AnswerRe: Question Arduino programming + joystick + bulbs Pin
CPallini11-May-21 20:23
mveCPallini11-May-21 20:23 
AnswerRe: Question Arduino programming + joystick + bulbs Pin
Richard MacCutchan11-May-21 21:47
mveRichard MacCutchan11-May-21 21:47 
QuestionWaitForMultipleObjects getting access violation in Worker Thread Pin
ForNow9-May-21 13:32
MemberForNow9-May-21 13:32 

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.