Very simple: passing parameters

F

Francogrex

I forgot all my C programming a little help would do please:
I want to write a very simple program that passes two command line
parameters like below. (The aim of this simple test is for later to
call C programs from common lisp applications thorough the so-called
foreign function interface). Thanks

int main (int x, int y)
{
....
...x+y
....
}

and then call the program (say it's called test) at the prompt:
 
J

Joachim Schmitz

Francogrex said:
I forgot all my C programming a little help would do please:
I want to write a very simple program that passes two command line
parameters like below. (The aim of this simple test is for later to
call C programs from common lisp applications thorough the so-called
foreign function interface). Thanks

int main (int x, int y)

Wrong.

int main(inf argc, char *argv[])
{
...
..x+y

something like
...strtol(argv[1]) + strtol(argv[2]
...
}

and then call the program (say it's called test) at the prompt:

Bye, Jojo
 
K

Kenny McCormack

Francogrex said:
I forgot all my C programming a little help would do please:
I want to write a very simple program that passes two command line
parameters like below. (The aim of this simple test is for later to
call C programs from common lisp applications thorough the so-called
foreign function interface). Thanks

int main (int x, int y)

Wrong.

int main(inf argc, char *argv[])

Wrong.

int main(int argc, char *argv[])

Always glad to be of assistance, in the time honored, CLC way.

Incidentally, if you tried to compile your stuff before posting it on
this public newsgroup, you'd have found the error, and saved us all a
lot of public embarassment.
 
J

Joachim Schmitz

Kenny said:
Francogrex said:
I forgot all my C programming a little help would do please:
I want to write a very simple program that passes two command line
parameters like below. (The aim of this simple test is for later to
call C programs from common lisp applications thorough the so-called
foreign function interface). Thanks

int main (int x, int y)

Wrong.

int main(inf argc, char *argv[])

Wrong.

int main(int argc, char *argv[])

Always glad to be of assistance, in the time honored, CLC way.

a billion thanks for spotting this stupid typo of mine...

Bye, Jojo
 
K

Kenny McCormack

Always glad to be of assistance, in the time honored, CLC way.

a billion thanks for spotting this stupid typo of mine...[/QUOTE]

Sure, no problem. Anytime.

But as I said, if you had just taken the time to run it through a
compiler, like all the CLC regs urge the newbies to do (and get all
hypersensitive about it if/when they don't), you'd have caught the error
in time.

Just sayin'...
 
J

Joachim Schmitz

Richard said:
blargg said:
Kenny McCormack wrote:
[...]
Incidentally, if you tried to compile your stuff before posting
it on this public newsgroup, you'd have found the error, and
saved us all a lot of public embarassment.
^
But not yourself, apparently.

You have an English compiler?

Conforming to what standard? English99?

Bye, Jojo
 
I

Ian Collins

Joachim said:
Richard said:
blargg said:
Kenny McCormack wrote:
[...]
Incidentally, if you tried to compile your stuff before posting
it on this public newsgroup, you'd have found the error, and
saved us all a lot of public embarassment.
^
But not yourself, apparently.

You have an English compiler?

Conforming to what standard? English99?

English1500 is probably more portable, it predates the language fork :)
 
R

Richard

Francogrex said:
I forgot all my C programming a little help would do please:
I want to write a very simple program that passes two command line
parameters like below. (The aim of this simple test is for later to
call C programs from common lisp applications thorough the so-called
foreign function interface). Thanks

int main (int x, int y)

Wrong.

int main(inf argc, char *argv[])

Wrong.

int main(int argc, char *argv[])

Always glad to be of assistance, in the time honored, CLC way.

Incidentally, if you tried to compile your stuff before posting it on
this public newsgroup, you'd have found the error, and saved us all a
lot of public embarassment.

Indeed.

I spent ages scratching my head on this one. I had assumed someone as
generally pedantic, picky and downright rude as JoJo would have been
correct. It was a relief to realise it was not my non compliant
compiler's fault but his rush to be rude, picky and pedantic that
caused the error. Interestingly in that rush he failed to realise the OP
was asking a question, not making a statement.
 
G

Guest

Richard Heathfield wrote:


Conforming to what standard? English99?

I am firmly opposed to the wide adoption of this standard and consider
many of the earlier EnglishXX standards to be obviously superior.
 
G

Guest

I forgot all my C programming a little help would do please:
I want to write a very simple program that passes two command line
parameters like below. (The aim of this simple test is for later to
call C programs from common lisp applications thorough the so-called
foreign function interface). Thanks

you might be better off on a Lisp group for this. They
will know all about the FFI whilst most of don't. I think
it far more likely you call C functions from Lisp rather than
C programs.

int main (int x, int y)

this isn't a valid form of main()

{
...
..x+y
...

}

and then call the program (say it's called test) at the prompt:

#include <stdlib.h>
#include <stdio.h>

int main (int argc, char *argv[])
{
printf ("%d\n", atoi(argv[1]) + atoi(argv[2]));
return 0;
}

this is rather non-robust

I suspect you want something more like this

int test (int x, int y)
{
return x + y;
}


--
Nick Keighley

A ruby trembled. Two tourmaline nets failed to rectify the laser beam.
A diamond noted the error. Both the error and the correction went into
the general computer.
Corwainer Smith "The Dead Lady of Clown Town"
 
R

Richard Tobin

Conforming to what standard? English99?
[/QUOTE]
I am firmly opposed to the wide adoption of this standard and consider
many of the earlier EnglishXX standards to be obviously superior.

I suppose standardisation might help resist the embrace-and-extend
techniques used by the biggest vendor of the English language, viz.
the USA.

-- Richard
 
E

Eric Sosman

I am firmly opposed to the wide adoption of this standard and consider
many of the earlier EnglishXX standards to be obviously superior.

"Be not the first by whom the new are tried,
Nor yet the last to lay the old aside."
-- Alexander Pope
 
K

Kenny McCormack

you might be better off on a Lisp group for this. They
will know all about the FFI whilst most of don't. I think
it far more likely you call C functions from Lisp rather than
C programs.



this isn't a valid form of main()

Maybe not, but it is more valid than the alternative proposed by one of
the regs here in this newsgroup. The form proposed by the OP will, on
most systems, both compile and run correctly. The alternative proposed
by the CLC reg will do neither.
 
J

Joachim Schmitz

Richard said:
Francogrex wrote:
I forgot all my C programming a little help would do please:
I want to write a very simple program that passes two command line
parameters like below. (The aim of this simple test is for later to
call C programs from common lisp applications thorough the
so-called foreign function interface). Thanks

int main (int x, int y)

Wrong.

int main(inf argc, char *argv[])

Wrong.

int main(int argc, char *argv[])

Always glad to be of assistance, in the time honored, CLC way.

Incidentally, if you tried to compile your stuff before posting it on
this public newsgroup, you'd have found the error, and saved us all a
lot of public embarassment.

Indeed.

I spent ages scratching my head on this one. I had assumed someone as
generally pedantic, picky and downright rude as JoJo would have been
correct. It was a relief to realise it was not my non compliant
compiler's fault but his rush to be rude, picky and pedantic that
caused the error. Interestingly in that rush he failed to realise the
OP was asking a question, not making a statement.

I know that I shouldn't be responding to trolls, but please enlighten me
where (in this thread) I've been rude, picky or pedantic.
The OP used main() wrongly, I've told him about that (and made an obvious
typo, big deal).

Bye, Jojo

PS: I personally find it somewhat rude that you even don't make an effort
spell my (nick-)name correctly. That 2nd "j" is lower case...
 
F

Francogrex

I suspect you want something more like this

int test (int x, int y)
{
    return x + y;

}

Indeed that's what I wanted. thanks. I should have known that i had to
use another name than main to make it work. it works now I also could
call the C function from CL using ffi. thanks again.
 
J

Joachim Schmitz

Francogrex said:
Indeed that's what I wanted. thanks. I should have known that i had to
use another name than main to make it work. it works now I also could
call the C function from CL using ffi. thanks again.

Apparently Nick's intention detection is far better than mine.

You did explicitly ask about passing command line parameters.

Bye, Jojo
 
R

Richard Bos

Golden California Girls said:
English99 isn't a standard, but The Chicago Manual of Style is.

On the distaff side of the herring pond, maybe. Not in the civilised
world.

Richard
 
R

Richard Bos

Golden California Girls said:
And what is used on that backwards rock?

On the backwards rock, as you already wrote, the Chicago Manual of Style
is used.

Richard
 
R

Richard Bos

Golden California Girls said:
You seem to have your rocks confused.

I don't think so, colony-boy.
More seriously, are the Cambridge or Oxford publications more authoritative?

Oxford; I don't think Cambridge publishes dictionaries.

Richard
 
M

Martin Ambuhl

Richard said:
Oxford; I don't think Cambridge publishes dictionaries.

Cambridge publishes a wide range of dictionaries. Your error is a
common one on comp.lang.c: taking wild guesses at things off-topic.
Stick to things topical and you have less chance of being so very wrong.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,102
Messages
2,570,645
Members
47,245
Latest member
ShannonEat

Latest Threads

Top