[an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] (none) [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] (none) [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive]
 
[an error occurred while processing this directive] [an error occurred while processing this directive]
Skåne Sjælland Linux User Group - http://www.sslug.dk Home   Subscribe   Mail Archive   Forum   Calendar   Search
MhonArc Date: [Date Prev] [Date Index] [Date Next]   Thread: [Date Prev] [Thread Index] [Date Next]   MhonArc
 

Re: [PROGRAMMERING] array af funktioner, initialisering og kald af dem.



Hej

Tak for de i grund og bund to forskellige tilgangsvinkler.
Begge er interessanted. Jeg er lidt i tvivl om Roberts brug af maps eller std::maps. Jeg er nok ikke dygtigt nok, endnu. Hvor kan man læse lidt om det, da det åbenbart ikke er med i min basale viden om C++ ?


Peter

Michael Rasmussen wrote:
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

On Wed, 21 Feb 2007 19:31:16 +0100
Hans-Christian Stadler <sslug@sslug> wrote:

Hvis det nu skal være C++ (--) = C

Nu er det ikke for at være krakiler, men hvis intentionen er, at det
skal være C, skal dit eksempel tilrettes til følgende:

#include <stdio.h>

int adecode(char *p, char *t);
int vdecode(char *p, char *t);
int tdecode(char *p, char *t);

int (*f[3])(char *p, char *t);

void setup(int index, int (*decode)(char *p, char *t)) {
	f[index] = decode;
}

int call_f(int index, char *p, char *t) {
	return f[index](p, t);
}

int main (int argc, char *argv[])
{
	int i;

	setup(0, adecode);
	setup(1, vdecode);
	setup(2, tdecode);
	for (i=2; i>=0; --i)
		call_f(i, "hej", " der");
	return 0;
}

int adecode(char *p, char *t) {
	printf("adecode: %s%s\n", p, t);
	return 0;
}

int vdecode(char *p, char *t) {
	printf("vdecode: %s%s\n", p, t);
	return 0;
}

int tdecode(char *p, char *t) {
	printf("tdecode: %s%s\n", p, t);
	return 0;
}

Den resulterende binære fil fylder også 25% mindre.
- -rwxr-xr-x 1 mir  mir    7469 2007-02-21 19:44 test_c
- -rwxr-xr-x 1 mir  mir    9503 2007-02-21 19:40 test_cc

$ dpkg -s gcc
Package: gcc
Status: install ok installed
Priority: standard
Section: devel
Installed-Size: 64
Maintainer: Debian GCC Maintainers <sslug@sslug>
Architecture: i386
Source: gcc-defaults (1.50)
Version: 4:4.1.1-15

$ dpkg -s g++
Package: g++
Status: install ok installed
Priority: standard
Section: devel
Installed-Size: 40
Maintainer: Debian GCC Maintainers <sslug@sslug>
Architecture: i386
Source: gcc-defaults (1.50)
Version: 4:4.1.1-15

- -- Hilsen/Regards
Michael Rasmussen
http://keyserver.veridis.com:11371/pks/lookup?op=get&search=0xE3E80917
A computer is like air conditioning: it becomes useless when you open
windows.
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.6 (GNU/Linux)


iD8DBQFF3JQEVErYVePoCRcRAnccAJoC1jQjBmjk7AvoOuR7A3eifp8ZYwCaA0AI
BqNCgZNNqtaWZNFlu67Zh7M=
=EzNK
-----END PGP SIGNATURE-----



 
Home   Subscribe   Mail Archive   Index   Calendar   Search

 
 
Questions about the web-pages to <www_admin>. Last modified 2007-03-01, 02:01 CET [an error occurred while processing this directive]
This page is maintained by [an error occurred while processing this directive]MHonArc [an error occurred while processing this directive] # [an error occurred while processing this directive] *