comp.lang.ada
 help / color / mirror / Atom feed
From: "Luis P. Mendes" <luislupeXXX@gmailXXX.com>
Subject: Re: Need some light on using Ada or not
Date: 20 Feb 2011 00:20:56 GMT
Date: 2011-02-20T00:20:56+00:00	[thread overview]
Message-ID: <4d605e67$0$23753$14726298@news.sunsite.dk> (raw)
In-Reply-To: 7ibvl6tn4os3njo3p4kek9kop44nke3n7t@4ax.com

Sat, 19 Feb 2011 13:07:58 +0000, Brian Drummond escreveu:
 
> Ada can easily bind to C libraries, it's standard and well documented.
> 
> However there already exist bindings to some graphics libraries and data
> visualisation tools - look at GTKAda and QTAda for GUI and some graphics
> bindings, and PLPlot for data visualisation. One of these may work for
> you.
> 
> C++ bindings are also possible, but with some work and (currently) some
> limitations.
> A GCC recent enough to support "-f-dump-ada-spec" will auto-generate an
> Ada spec from C++ sources, which will save a lot of the work. (Adacore
> "libre" 2010 has it; the FSF GCC 4.5.0 has not. Anyone know if it made
> it into 4.5.1 or 4.6.0?)
> 
> I would currently treat that binding as a starting point rather than a
> complete solution.  For example, it (libre "GPL2010" from Adacore) has
> problems with templates. (Especially when your well-proven C++ template
> library still has bugs that Ada generics would have caught first time
> through the compiler!)

Would you mind giving me an example?
Please consider the following C++ code:
===== header file
$ cat aleatorio.h 
#ifndef GUARD_aleatorio_h
#define GUARD_aleatorio_h

#include <unistd.h>
#include <ctime>
#include <cstdlib>

void iniciarSemente();
double gerarAleatorio(int a, int b);
int gerarAleatorioInteiro(int a, int b);
int arredondar(double res);

#endif

===== source file
$ cat aleatorio.cpp 
#include <unistd.h>
#include <ctime>
#include <cstdlib>
#include "aleatorio.h"
#include <math.h>

using std::srand;
using std::rand;

void iniciarSemente() {
	srand(time(NULL));
	//srand(10);	//gerar sempre a mesma semente para comparacoes
}

double gerarAleatorio(int a, int b) {
	return (b-a) * ( (double) rand()/RAND_MAX) + a;
}

int arredondar(double res) {
	return (res > 0.0) ? floor(res + 0.5) : ceil(res - 0.5);
}

int gerarAleatorioInteiro(int a, int b) {
	// verificar colocação do (int), parêntesis 
	float res;
	res = gerarAleatorio(a, b);
	return arredondar(res);
}

=====

From Ada, how can I use these h and cpp files to call, for example, 
gerarAleatorioInteiro(0,10)?


Luis



  parent reply	other threads:[~2011-02-20  0:20 UTC|newest]

Thread overview: 46+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-02-18 22:52 Need some light on using Ada or not Luis P. Mendes
2011-02-18 23:58 ` Georg Bauhaus
2011-02-19 14:25   ` Simon Wright
2011-02-19  0:20 ` Edward Fish
2011-02-20  0:13   ` Luis P. Mendes
2011-02-20  1:36     ` Marc A. Criley
2011-02-20  9:59     ` mockturtle
2011-02-20 10:37     ` Brian Drummond
2011-02-20 11:08     ` Ludovic Brenta
2011-03-01  8:10     ` Adrian Hoe
2011-03-01  8:29       ` Thomas Løcke
2011-03-04 13:34         ` Adrian Hoe
2011-02-19  8:43 ` Vadim Godunko
2011-02-19 13:07 ` Brian Drummond
2011-02-19 14:17   ` Simon Wright
2011-02-19 18:02     ` Brian Drummond
2011-02-19 18:07       ` Bill Findlay
2011-02-20 10:42         ` Brian Drummond
2011-02-19 14:36   ` Georg Bauhaus
2011-02-19 18:25     ` Brian Drummond
2011-02-20 14:34       ` Brian Drummond
2011-02-20 15:45         ` jonathan
2011-02-20 16:18           ` Brian Drummond
2011-02-20 19:49           ` Pascal Obry
2011-02-20 19:57             ` Brian Drummond
2011-02-20 20:10               ` jonathan
2011-02-20 21:15                 ` Pascal Obry
2011-02-20 21:26                   ` Vinzent Hoefler
2011-02-20 21:33                     ` Vinzent Hoefler
2011-02-20 21:36                     ` Pascal Obry
2011-02-20 21:50                       ` Vinzent Hoefler
2011-02-20 22:18                   ` jonathan
2011-02-20 22:47               ` Simon Wright
2011-02-21 12:52                 ` Brian Drummond
2011-02-21 13:44                   ` Simon Wright
2011-02-24  0:19                     ` Brian Drummond
2011-02-24  7:41                       ` Jacob Sparre Andersen
2011-02-22  2:15                   ` Shark8
2011-02-20 16:42       ` jonathan
2011-02-20 20:02         ` Brian Drummond
2011-02-20  0:20   ` Luis P. Mendes [this message]
2011-02-20 10:50     ` Brian Drummond
2011-02-20 19:54     ` Brian Drummond
2011-02-23 22:19       ` Luis P. Mendes
2011-02-24 17:06         ` Brian Drummond
2011-02-27 17:51           ` Luis P. Mendes
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox