Click here to Skip to main content
15,891,633 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: Structure containing byte[1] as member variable Pin
jschell6-Sep-12 8:31
jschell6-Sep-12 8:31 
GeneralRe: Structure containing byte[1] as member variable Pin
Chris Losinger6-Sep-12 9:19
professionalChris Losinger6-Sep-12 9:19 
GeneralRe: Structure containing byte[1] as member variable Pin
jschell13-Sep-12 8:07
jschell13-Sep-12 8:07 
GeneralRe: Structure containing byte[1] as member variable Pin
Chris Losinger13-Sep-12 8:11
professionalChris Losinger13-Sep-12 8:11 
GeneralRe: Structure containing byte[1] as member variable Pin
jschell14-Sep-12 8:41
jschell14-Sep-12 8:41 
GeneralRe: Structure containing byte[1] as member variable Pin
Stefan_Lang5-Sep-12 1:57
Stefan_Lang5-Sep-12 1:57 
GeneralRe: Structure containing byte[1] as member variable Pin
jschell5-Sep-12 11:26
jschell5-Sep-12 11:26 
GeneralRe: Structure containing byte[1] as member variable Pin
Stefan_Lang6-Sep-12 2:53
Stefan_Lang6-Sep-12 2:53 
jschell wrote:
First part is an opinion but feel free to substantiate it.

I have deliberately used "may" because it does indeed reflect an opinion. From a C++ programmers point of view it's terribad. From a C-programmers view it admittedly doesn't look bad at all. It looks like a reasonable workaround to overcome a limitation of the language. However, using such structs breaks expectations, such as
a) that a data structure is always the same size, and that size can be determined using sizeof()
b) that an instance of that data structure looks exactly like defined in the header
c) that you can create instances normally, using alloc(sizeof(mystruct))

You need to make sure that everyone seeing that data structure definition in a header understands that (a), (b), and (c) above no longer hold, and what you are supposed to do instead. This information can only be passed by comments, not via source code, and the compiler has no way of telling whether you're doing it right.

I didn't know that this stuff is actually being supported by some compilers (or at least one?) Thanks for the link - you learn something new every day...
jschell wrote:
Just as you must be careful about anything involving pointers and memory in C/C++.

That is not quite the same. See my comments above. Managing pointers and avoiding leaks is easy in comparison, and quite easily managed by a decent set of guidelines.

jschell wrote:
<layer>Except that is exactly the point - it isn't known at compile time.

Maybe it isn't. But maybe it is - and that is exactly my point.

An example would be a struct for storing string-based data fields from a database, where each column of a table may have a different size. Generally you'd query the field size before allocating the proper amount of memory for your struct. But when a function references a specific field, then you know at compile time which field that is, and how much memory you need. So you could define a sufficiently large memory block an the stack to store values within that function.

Not saying that this is a good idea: where one programmer might consider 2 characters to be "sufficient" to store a year entry, others accessing the same struct might expect 4 characters. Enter the Y2K crisis! Wink | ;)
GeneralRe: Structure containing byte[1] as member variable Pin
jschell6-Sep-12 8:28
jschell6-Sep-12 8:28 
AnswerRe: Structure containing byte[1] as member variable Pin
Richard MacCutchan4-Sep-12 9:07
mveRichard MacCutchan4-Sep-12 9:07 
GeneralRe: Structure containing byte[1] as member variable Pin
Rahul from Poona4-Sep-12 20:00
Rahul from Poona4-Sep-12 20:00 
GeneralRe: Structure containing byte[1] as member variable Pin
Richard MacCutchan4-Sep-12 21:46
mveRichard MacCutchan4-Sep-12 21:46 
AnswerRe: Structure containing byte[1] as member variable Pin
jschell4-Sep-12 11:46
jschell4-Sep-12 11:46 
QuestionFinding crash information using the MAP file in vs2005 Pin
neha_soni4-Sep-12 1:10
neha_soni4-Sep-12 1:10 
AnswerRe: Finding crash information using the MAP file in vs2005 Pin
David Crow4-Sep-12 2:35
David Crow4-Sep-12 2:35 
AnswerRe: Finding crash information using the MAP file in vs2005 Pin
krmed4-Sep-12 3:33
krmed4-Sep-12 3:33 
AnswerRe: Finding crash information using the MAP file in vs2005 Pin
Stephen Hewitt6-Sep-12 21:46
Stephen Hewitt6-Sep-12 21:46 
Question(SOLVED) make single executable file in vs2008 (MFC) Pin
jawadali4773-Sep-12 1:26
jawadali4773-Sep-12 1:26 
AnswerRe: make single executable file in vs2008 (MFC) Pin
pasztorpisti3-Sep-12 2:05
pasztorpisti3-Sep-12 2:05 
GeneralRe: make single executable file in vs2008 (MFC) Pin
jawadali4774-Sep-12 17:42
jawadali4774-Sep-12 17:42 
GeneralRe: make single executable file in vs2008 (MFC) Pin
pasztorpisti4-Sep-12 23:04
pasztorpisti4-Sep-12 23:04 
GeneralRe: make single executable file in vs2008 (MFC) Pin
jawadali4779-Sep-12 17:45
jawadali4779-Sep-12 17:45 
GeneralRe: make single executable file in vs2008 (MFC) Pin
pasztorpisti9-Sep-12 21:26
pasztorpisti9-Sep-12 21:26 
GeneralRe: make single executable file in vs2008 (MFC) Pin
jawadali47710-Sep-12 17:17
jawadali47710-Sep-12 17:17 
AnswerRe: make single executable file in vs2008 (MFC) Pin
Stephen Hewitt3-Sep-12 16:51
Stephen Hewitt3-Sep-12 16:51 

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.