Pomos okolu C++

Forum o svemu i svačemu, ALI vezanim za elektroniku.

Moderators: pedja089, stojke369, [eDo], trax, LAF

Post Reply
User avatar
DigiSoft
Napredujem
Napredujem
Posts: 161
Joined: 04-10-2006, 00:55
Location: Makedonija, Skopje

Pomos okolu C++

Post by DigiSoft »

Vaka znaci.

Vo memorija postoi adresa na primer 0x00123456 i na taa adresa ima funkcija printf. E sega jas sakam od moj program vo C++ da ja povikam ovaa funkcija no ne kako printf tuku preku nejzinata memoriska adresa.

Doznav deka za ova se koristi komandata

reinterpret_cast

deklaracijata na printf funkcijata e

int printf(const char *, ...);

Znaci moeto prasanje e kako ovaa deklaracija na printf da ja povrzam preku reinterpret_cast so memoriskata adresa 0x00123456 taka sto ponatamu vo programot kje si ja koristam kako normalna funkcija printf.

Aj ve molam za pomos zosto nikako ne moze da mi vleze ova vo glava.

Fala
User avatar
pepi
Odlično uznapredovao
Odlično uznapredovao
Posts: 964
Joined: 04-12-2006, 18:58
Location: Rijeka, HR
Contact:

Post by pepi »

I'd like to help, but I don't understand you :shock:
User avatar
DigiSoft
Napredujem
Napredujem
Posts: 161
Joined: 04-10-2006, 00:55
Location: Makedonija, Skopje

Post by DigiSoft »

Ok sorry I'll translte.

I am trying to define and call a function based on its location in memory. For example, if I have a function printf and I have the location of this function in memory, say its address is 0x00123456, what is the most proper way to define and call this function (along with the arguments)?

How can I call the function by using only is memory address, without it being defined in my code.
A real world example: If an external program had a function that I want called, and I have its address, I need to know how to cast a function like this.
I heard I should use reinterpret_cast but I dont know how to connect the printf with 0x00123456 adress.

With one word I want to replace printf memory adress 0x00123456 with int printf(const char *, ...); so I can use this printf in my code. I don't want to use stdio. h because this function is already compiled and it is at 0x00123456
User avatar
imocanin
Odlično uznapredovao
Odlično uznapredovao
Posts: 523
Joined: 08-01-2007, 12:08
Location: Imotski, Split

Post by imocanin »

program kada se prevodi iz viseg jezika kompajler ga prevede se u asemblerski oblik...kada se izvodi nema isti oblik kao u visem jeziku...funkcija npr printf(); nije definirana samo tako i daje ispis na ekran nego sadrzi niz instrukcija potrebnih za to...s toga kad se ta funkcija prevede nalazi se na vise lokacija u memoriji ne samo u jednoj...ne razumim sta zelis tocno izvesti
Cirkus Kolorado :D
User avatar
VasilyZaitsev
Pravo uznapredovao :)
Pravo uznapredovao :)
Posts: 219
Joined: 03-04-2007, 10:37
Location: Sarajevo, BIH

Post by VasilyZaitsev »

Here is everything you'll need: http://www.newty.de/fpt/index.html

Making a function pointer is quite simple, although you must be very careful or your application will crash from time to time.
Post Reply