Welcome, Guest. Please login or register.

Author Topic: View the Outbox  (Read 4277 times)

Description:

0 Members and 1 Guest are viewing this topic.

Offline Karlos

  • Sockologist
  • Global Moderator
  • Hero Member
  • *****
  • Join Date: Nov 2002
  • Posts: 16867
  • Country: gb
  • Thanked: 4 times
    • Show only replies by Karlos
Re: View the Outbox
« Reply #29 from previous page: January 29, 2007, 12:44:54 AM »
@Jose

I guess it's not everybody's cup of tea. He wouldn't be alone in hating it.

*mental image of gamecube pops up for no apparent reason*
int p; // A
 

Offline AMC258

  • Hero Member
  • *****
  • Join Date: Jan 2007
  • Posts: 877
    • Show only replies by AMC258
    • http://www.AMC258.com/
Re: View the Outbox
« Reply #30 on: January 29, 2007, 01:11:18 AM »
Forwards or backwards depends on your point of view.
If you are a C programmer, C is forwards and everything else is backwards.  If you are not a C programmer, C is backwards and everything else is forwards.
I gave C a fair chance 15 years ago.  I just can't get over the counterintuitivity.
Get up!  Get up!  Get outta here!  GONE!
  - Bob Uecker
 

Offline Jose

  • Hero Member
  • *****
  • Join Date: Feb 2002
  • Posts: 2869
    • Show only replies by Jose
Re: View the Outbox
« Reply #31 on: January 29, 2007, 01:26:39 AM »
C rules:) Actually I've for the 1st time tryed to code some stuff (that general coder thing, unfinished...) that made me see some actual limitations of C. The main loop for array handling for each data type had blocks of code that followed the same control statements. If I was to code it for each type separately it would have a bunch of repeated code. So I abstracted it using function pointers:) But I think in the end it was to be much less efective because of the constant function calls within the loop, wich supposedly take memo of registers, stack etc, between function calls. C++ would have handled this internaly with a simple goto, right ? I tried to avoid the overhead using only a single pointer as argument, wich points to the set of arguments that all the "objects" might need. It still won't be as fast but probably almost the same (provided compilers optimize multiple pointer acess wich is only logical that they do, right ?)...
...
I need some sleep... :-)
\\"We made Amiga, they {bleep}ed it up\\"
 

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: View the Outbox
« Reply #32 on: January 29, 2007, 03:34:01 AM »
Quote
Actually I've for the 1st time tryed to code some stuff (that general coder thing, unfinished...) that made me see some actual limitations of C. The main loop for array handling for each data type had blocks of code that followed the same control statements. If I was to code it for each type separately it would have a bunch of repeated code.

Ever heard of macros? ;-)
 

Offline LoadWB

  • Hero Member
  • *****
  • Join Date: Jul 2006
  • Posts: 2901
  • Country: 00
    • Show only replies by LoadWB
Re: View the Outbox
« Reply #33 on: January 29, 2007, 05:13:12 AM »
All I can say is that C is a dream compared to RPG.  RPG is a nightmare compared to COBOL :-)
 

Offline Karlos

  • Sockologist
  • Global Moderator
  • Hero Member
  • *****
  • Join Date: Nov 2002
  • Posts: 16867
  • Country: gb
  • Thanked: 4 times
    • Show only replies by Karlos
Re: View the Outbox
« Reply #34 on: January 29, 2007, 12:57:08 PM »
Quote

Piru wrote:
Quote
Actually I've for the 1st time tryed to code some stuff (that general coder thing, unfinished...) that made me see some actual limitations of C. The main loop for array handling for each data type had blocks of code that followed the same control statements. If I was to code it for each type separately it would have a bunch of repeated code.

Ever heard of macros? ;-)


Or just use C++ where this could be quite readily handled with a template ;-)

int p; // A
 

Offline Jose

  • Hero Member
  • *****
  • Join Date: Feb 2002
  • Posts: 2869
    • Show only replies by Jose
Re: View the Outbox
« Reply #35 on: January 29, 2007, 08:31:54 PM »
I guess macros would do just fine, as templates:)
But both also repeat the code internaly (from my limited knowledge of C++ templates also do that), wich leads to unecessarily bigger code. I think a C++ class would solve it better, without duplicating code and allowing for faster code I think (?) (compared to function pointers). BTW, is there a way to use function pointers without the usual overhead of function calls ? Inline functions come to mind, but those also duplicate the code...
\\"We made Amiga, they {bleep}ed it up\\"
 

Offline Karlos

  • Sockologist
  • Global Moderator
  • Hero Member
  • *****
  • Join Date: Nov 2002
  • Posts: 16867
  • Country: gb
  • Thanked: 4 times
    • Show only replies by Karlos
Re: View the Outbox
« Reply #36 on: January 29, 2007, 09:14:03 PM »
@Jose

That depends. The C preprocessor knows absolutely nothing about C as a language and will happily create the most illegal code possible if you aren't careful.

Templates in C++, on the other hand, are part of the language specification and have strict rules.

As for a class versus a template class, it really depends on your particular needs.

If you need run time polymorphic behaviuour and speed is not absolutely critical, abstract classes are the way to go.

Templates, on the other hand, are designed to allow you to create "generic" code. Every version of a template you make results in something like a new handwritten class based on your template parameters being created by the compiler. Consequently code can bloat a lot if you are not careful. Thankfully, its easy to specialise templates to avoid that. For example, suppose you made some container template "MyContainer", you could save a lot by making a specialisation for pointers by making the MyContaier as a specialisation for all MyContainer. In effect, what you end up with is a single class that handles void* and a bunch of templates that just wrap it with type-safe behaviour, adding no additional code to the executable.
int p; // A
 

Offline Jose

  • Hero Member
  • *****
  • Join Date: Feb 2002
  • Posts: 2869
    • Show only replies by Jose
Re: View the Outbox
« Reply #37 on: January 29, 2007, 09:56:53 PM »
@So I guess using a class the resulting code will be like adding a switch inside the loop for each type(not that bad admiting that the compiler optimizes it to an array of goto's indexed by the variable) ? Maybe I'll just use that next time:-)
\\"We made Amiga, they {bleep}ed it up\\"