Welcome, Guest. Please login or register.

Author Topic: sizeof (*VarPtr) possible ?  (Read 5318 times)

Description:

0 Members and 1 Guest are viewing this topic.

Offline Piru

  • \' union select name,pwd--
  • Hero Member
  • *****
  • Join Date: Aug 2002
  • Posts: 6946
    • Show only replies by Piru
    • http://www.iki.fi/sintonen/
Re: sizeof (*VarPtr) possible ?
« Reply #14 from previous page: January 30, 2007, 11:12:58 PM »
@Karlos

Nor does it handle sizeof variable.
 

Offline Karlos

  • Sockologist
  • Global Moderator
  • Hero Member
  • *****
  • Join Date: Nov 2002
  • Posts: 16879
  • Country: gb
  • Thanked: 5 times
    • Show only replies by Karlos
Re: sizeof (*VarPtr) possible ?
« Reply #15 on: January 31, 2007, 12:59:43 AM »
Quote

Piru wrote:
@Karlos

Nor does it handle sizeof variable.


Of course not. The point was that it is possible to use a macro to evaluate the size of a structure/primitive type, nothing more. Just to demonstrate that (some of) the behaviour of sizeof() could be implemented as a macro, even if the actual sizeof() itself is not.

@Koafter

Agreed, it's disgusting and I'd want to shoot anybody I saw using anything quite like that*.

(*I have used some ugly macros in my time but only to abstract something that simply couldn't be represented more cleanly in the language itself. The above example naturally does not fall into this category).

C is a fantastic language but when you do end up having to depend on macros for things that you could readily do in C++ with inline functions and templates you really do see the point in moving up the language food chain ;-) Other than conditional compilation, I rarely use macros in C++ for anything.

I make no secret of the fact I regard C++ as utterly superior to C. Not because of the OO features per se (which I do like of course) but simply because it provides much cleaner ways of doing things that in C you would otherwise end up using the preprocessor or other contrivances for. It also provides greater error checking and general robustness and last but not least, still allows you to do things low level when you need to.
int p; // A
 

Offline koaftder

  • Hero Member
  • *****
  • Join Date: Apr 2004
  • Posts: 2116
    • Show only replies by koaftder
    • http://koft.net
Re: sizeof (*VarPtr) possible ?
« Reply #16 on: January 31, 2007, 01:15:31 AM »
Quote

I make no secret of the fact I regard C++ as utterly superior to C. Not because of the OO features per se (which I do like of course) but simply because it provides much cleaner ways of doing things that in C you would otherwise end up using the preprocessor or other contrivances for. It also provides greater error checking and general robustness and last but not least, still allows you to do things low level when you need to.


Amen brother! A lot of what I do microcontroller wise is straight C, and my other projects are mostly procedural, but I really appreciate stuff from C++ land that makes my life easier, even though i don't usually do OOP unless i'm doing an MFC app, c++ stuff thats not OOP makes life easier for the C programmer.
 

Offline Karlos

  • Sockologist
  • Global Moderator
  • Hero Member
  • *****
  • Join Date: Nov 2002
  • Posts: 16879
  • Country: gb
  • Thanked: 5 times
    • Show only replies by Karlos
Re: sizeof (*VarPtr) possible ?
« Reply #17 on: January 31, 2007, 01:24:16 AM »
Generally, I use the procedural paradigm where it makes sense and OO paradigm where it makes sense :-) I prefer the latter and for most systems I work on it's the right choice, but there are naturally lots of smaller things you have to do where it is just overkill.

C++ is so good simply because it gives you the choice. Unlike OO "pure" languages (read Java; forever lambasting C++ for its awkard syntax and then adopting the template syntax for its generics :lol:)) which force you to apply it to the simplest cases and of course procedural languages which make it awkward to do at all :-)
int p; // A