:: Re: [DNG] semantic of sizeof operat…
Forside
Slet denne besked
Besvar denne besked
Skribent: s
Dato:  
Til: dng
Emne: Re: [DNG] semantic of sizeof operator in C
Hello guys,
First of all, I think that this subject derailed to a diferent subject.

I Apologise for give my opinion on a concrete subject, because, I never felt it would turn out "to be almost personal.."

My Opinion is based on the Idea that we should not create extra complications,
When we are ourselfs, defining a fixed size of something kown has a multiple of the minimum size alocable in memory..

In the Case, **only focusing only in the case**..
We had a Array used has a buffer with 512 bytes of fixed size..
So it was a pointer for something multiple of minimum size that could be alocated..

So in this situation sizeof or sizeof '*array', by the way( since sizeof is **not** a function but a unary operator.. ),
Doesn't make any sense at all ..
Why should we be calculating the size of a buffer, if we ourselfs dictated the fixed size and its a multiple of 'char' type, and also a multiple of 2^n??
Why are we calculating its size in all aplication were it is used, at compile time?

You can simply use a MACRO instead..
# define BUFFER_SIZE 512
In the pré-conpilation process, Macro will be substituted in text,
And no need to calculate nothing in the code, anny way a lot of pre-processing will occur, wether you want or not..

This was the motiff why I gave my sincere opinion, and nothing more than that, only to try to help @aitor..

Off course, if you have to allocate memory for structs/unions, things could be dynamic a bit.. or at least they were in the past..
To be honest, I don't recall if sizeof '*truct', does padding, or if it suppress bytes by itself right now( I do it by myself in the struct section declaration, since I don't allow the compiler to take "his opinions" has mines.., ... I am the one doing the code.. ),
But that is another thing, and not related with the code in cause..

Like @Didier noticed before,
In **this concrete case**, it has more to do with Code Style, than anything else!!

The code Generated will be similar,
But with a Macro seems to me, to be better..
Like I said, you don't be all the time in the code, asking compiler to find the size of something that you, **yourself**, created with fixed size, and a multiple of 2^n bytes, ... you know the size... for sure!!

That been Said,
I only gave my honest/sincere opinion about the 'sizeof' vs 'Macro', for the **concrete** situation( I don't even read all code..only took a shot at it.. ).
I apologize to all of you, ... for the buzz, I afterall, created around this..

Best Regards,
--
tux
s@po <tuxd3v@???>