Jump to content

default args c++


JohnOne
 Share

Recommended Posts

I'm having problems where autoit is crashing when calling a function in a dll file.

I am trying to give the function optional parameters.

From what I have read, it seems you can do it in much

the same way as autoit.

I have tried in a number of ways including

//prototype

//declaration

void add(int i = 0);

void add(int i = 0){

//stuff

}

void add(int i);

void add(int i = 0){

//stuff

}

void add(int);

void add(int i = 0){

//stuff

}

etc...

in all cases I get a crash if I do not pass it something.

Is there a specific way of achieving this for libraries, like overloading?

EDIT:

func is __stdcall if that makes any difference.

Edited by JohnOne

AutoIt Absolute Beginners    Require a serial    Pause Script    Video Tutorials by Morthawt   ipify 

Monkey's are, like, natures humans.

Link to comment
Share on other sites

Optional parameters are not knowable at runtime. They are compile time constants ONLY. The reason they work in C++ when you include a header is because the header declares it so the compiler inserts it if you ignore it. If you are using a non-C++ language or not using the header which declares the default value, you must specify it like a normal parameter.

Link to comment
Share on other sites

JohnOne, it is my understanding that the prototype is where you declare defaults and the actual function does not have defaults. Eg:

int main(int a = 42, char b = 'a');  /* Prototype */

int main(int a, char <img src='http://www.autoitscript.com/forum/public/style_emoticons/<#EMO_DIR#>/cool.png' class='bbc_emoticon' alt='B)' /> {  /* Function */
  /* blah blah */
}

In my (little) experience, this is the correct way to do this.

[font="Comic Sans MS"]My code does not have bugs! It just develops random features.[/font]My Projects[list][*]Live Streaming (Not my project, but my edited version)[right]AutoIt Wrappers![/right][/list]Pure randomness[list][*]Small Minds.......................................................................................................[size="1"]Simple progress bar that changes direction at either sides.[/size][*]ChristmasIt AutoIt Christmas Theme..........................................................[size="1"]I WAS BOOOORED![/size][*]DriveToy..............................................................................................................[size="1"]Simple joke script. Trick your friends into thinking their computer drive is haywire![/size][/list]In Development[list][*]Your Background Task Organiser[*]AInstall Second Generation[/list]BEFORE POSTING ON THE FORUMS, TRY THIS:

%programfiles%/AutoIt3/autoit3.chm
Link to comment
Share on other sites

Johnone, what you are trying to do is impossible. Optional parameters is only syntactic sugar resolved at compiletime as richard says. The function still expects the last parameter, hence you are corrupting the stack.

Normally, when you have default parameters, you set them to 0 - and the called function recognizes this as a default parameters. Eg:

void foo(int a, char * string) {
    if(!string) { // user called it like foo(5, NULL);
        //handle
    } else {
        //work with it
    }
    ...

}

Else you have to get into variadic functions, or passing an array of parameters and a count.

E: I guess you could overload the functions, afaik _stdcall gets exported as _[name]@[parameters_in_bytes]. However, you would still have to choose the right one.

JohnOne, it is my understanding that the prototype is where you declare defaults and the actual function does not have defaults. Eg:

int main(int a = 42, char b = 'a');  /* Prototype */

int main(int a, char <img src='http://www.autoitscript.com/forum/public/style_emoticons/<#EMO_DIR#>/cool.png' class='bbc_emoticon' alt='B)' /> {  /* Function */
  /* blah blah */
}

In my (little) experience, this is the correct way to do this.

You can also do it in the definition. Edited by Shaggi

Ever wanted to call functions in another process? ProcessCall UDFConsole stuff: Console UDFC Preprocessor for AutoIt OMG

Link to comment
Share on other sites

Yes the prototype is in a header file, and I'mm using VC++ VS2010.

AutoIt exits with -1073741819

............................................________........................

....................................,.-‘”...................``~.,..................

.............................,.-”...................................“-.,............

.........................,/...............................................”:,........

.....................,?......................................................,.....

.................../...........................................................,}....

................./......................................................,:`^`..}....

.............../...................................................,:”........./.....

..............?.....__.........................................:`.........../.....

............./__.(.....“~-,_..............................,:`........../........

.........../(_....”~,_........“~,_....................,:`........_/...........

..........{.._$;_......”=,_.......“-,_.......,.-~-,},.~”;/....}...........

...........((.....*~_.......”=-._......“;,,./`..../”............../............

...,,,___.`~,......“~.,....................`.....}............../.............

............(....`=-,,.......`........................(......;_,,-”...............

............/.`~,......`-...................................../...................

.............`~.*-,.....................................|,./.....,__...........

,,_..........}.>-._...................................|..............`=~-,....

.....`=~-,__......`,.........................................................

...................`=~-,,.,......................................................

................................`:,,...........................`..............__..

.....................................`=-,...................,%`>--==``.......

........................................_..........._,-%.......`...............

...................................,<`.._|_,-&``................`..............

Link to comment
Share on other sites

No, Jave (wild guess).

Good anyway!

This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...