Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.c++ > #8740 > unrolled thread
| Started by | Angus <anguscomber@gmail.com> |
|---|---|
| First post | 2011-08-12 11:58 -0700 |
| Last post | 2011-08-12 21:35 +0200 |
| Articles | 9 — 6 participants |
Back to article view | Back to comp.lang.c++
How to creat function to call eg int function1(int, ...) Angus <anguscomber@gmail.com> - 2011-08-12 11:58 -0700
Re: How to creat function to call eg int function1(int, ...) Victor Bazarov <v.bazarov@comcast.invalid> - 2011-08-12 15:22 -0400
Re: How to creat function to call eg int function1(int, ...) Juha Nieminen <nospam@thanks.invalid> - 2011-08-14 18:18 +0000
Re: How to creat function to call eg int function1(int, ...) Victor Bazarov <v.bazarov@comcast.invalid> - 2011-08-15 08:50 -0400
Re: How to creat function to call eg int function1(int, ...) Juha Nieminen <nospam@thanks.invalid> - 2011-08-15 13:33 +0000
Re: How to creat function to call eg int function1(int, ...) SG <s.gesemann@gmail.com> - 2011-08-15 06:41 -0700
Re: How to creat function to call eg int function1(int, ...) Nobody <nobody@nowhere.com> - 2011-08-15 19:25 +0100
Re: How to creat function to call eg int function1(int, ...) Juha Nieminen <nospam@thanks.invalid> - 2011-08-16 07:36 +0000
Re: How to creat function to call eg int function1(int, ...) "Alf P. Steinbach" <alf.p.steinbach:usenet@gmail.com> - 2011-08-12 21:35 +0200
| From | Angus <anguscomber@gmail.com> |
|---|---|
| Date | 2011-08-12 11:58 -0700 |
| Subject | How to creat function to call eg int function1(int, ...) |
| Message-ID | <a2e05ab3-f8f0-481f-abf2-35cdd422d934@fv14g2000vbb.googlegroups.com> |
Hi
I need to put all functions calling into a C API into a separate
source file unit. It is due to defines interfering with other code.
So to keep the possibly interfering code separate.
Anyway, most functions are eg int function2(int) so I just implement
in separate file like this:
int XXfunction1(int val) { return function(val) }
But I also have functions with variable arguments like this: extern
int function2(int, ...)
So how can I write my own function which calls that?
This doesn't seem to work:
int XXFunction2(int val, ...) {
return function2(val, ...);
}
How do I write the function?
Angus
[toc] | [next] | [standalone]
| From | Victor Bazarov <v.bazarov@comcast.invalid> |
|---|---|
| Date | 2011-08-12 15:22 -0400 |
| Message-ID | <j23ugp$n6o$1@dont-email.me> |
| In reply to | #8740 |
On 8/12/2011 2:58 PM, Angus wrote:
> I need to put all functions calling into a C API into a separate
> source file unit. It is due to defines interfering with other code.
> So to keep the possibly interfering code separate.
>
> Anyway, most functions are eg int function2(int) so I just implement
> in separate file like this:
> int XXfunction1(int val) { return function(val) }
;
>
> But I also have functions with variable arguments like this: extern
> int function2(int, ...)
>
> So how can I write my own function which calls that?
>
> This doesn't seem to work:
> int XXFunction2(int val, ...) {
> return function2(val, ...);
> }
>
> How do I write the function?
There is no portable way. Some compilers would let you call that
function with 'va_list' instead of the arguments. Consult your compiler
documentation or post to the newsgroup for your compiler.
V
--
I do not respond to top-posted replies, please don't ask
[toc] | [prev] | [next] | [standalone]
| From | Juha Nieminen <nospam@thanks.invalid> |
|---|---|
| Date | 2011-08-14 18:18 +0000 |
| Message-ID | <4e481180$0$2874$7b1e8fa0@news.nbl.fi> |
| In reply to | #8745 |
Victor Bazarov <v.bazarov@comcast.invalid> wrote: > There is no portable way. Some compilers would let you call that > function with 'va_list' instead of the arguments. Consult your compiler > documentation or post to the newsgroup for your compiler. Since when is the C89 standard (and hence by extension the C++98 standard) not portable?
[toc] | [prev] | [next] | [standalone]
| From | Victor Bazarov <v.bazarov@comcast.invalid> |
|---|---|
| Date | 2011-08-15 08:50 -0400 |
| Message-ID | <j2b4mb$af7$1@dont-email.me> |
| In reply to | #8842 |
On 8/14/2011 2:18 PM, Juha Nieminen wrote: > Victor Bazarov<v.bazarov@comcast.invalid> wrote: >> There is no portable way. Some compilers would let you call that >> function with 'va_list' instead of the arguments. Consult your compiler >> documentation or post to the newsgroup for your compiler. > > Since when is the C89 standard (and hence by extension the C++98 standard) > not portable? WTF are you talking about? I, for one, am tired of your riddles. Be verbose. I have no intention of guessing what you mean. V -- I do not respond to top-posted replies, please don't ask
[toc] | [prev] | [next] | [standalone]
| From | Juha Nieminen <nospam@thanks.invalid> |
|---|---|
| Date | 2011-08-15 13:33 +0000 |
| Message-ID | <4e492039$0$2807$7b1e8fa0@news.nbl.fi> |
| In reply to | #8857 |
Victor Bazarov <v.bazarov@comcast.invalid> wrote: > On 8/14/2011 2:18 PM, Juha Nieminen wrote: >> Victor Bazarov<v.bazarov@comcast.invalid> wrote: >>> There is no portable way. Some compilers would let you call that >>> function with 'va_list' instead of the arguments. Consult your compiler >>> documentation or post to the newsgroup for your compiler. >> >> Since when is the C89 standard (and hence by extension the C++98 standard) >> not portable? > > WTF are you talking about? I, for one, am tired of your riddles. Be > verbose. I have no intention of guessing what you mean. va_list is part of the C89 standard, yet you claim there is no portable way.
[toc] | [prev] | [next] | [standalone]
| From | SG <s.gesemann@gmail.com> |
|---|---|
| Date | 2011-08-15 06:41 -0700 |
| Message-ID | <1820cbc4-edc9-4c0f-bc90-4db16d6dcb83@b7g2000yqj.googlegroups.com> |
| In reply to | #8861 |
On 15 Aug., 15:33, Juha Nieminen wrote: > > va_list is part of the C89 standard, yet you claim there is > no portable way. I fail to see a contradiction here. Maybe you did not understand what this thread is about. -- SG
[toc] | [prev] | [next] | [standalone]
| From | Nobody <nobody@nowhere.com> |
|---|---|
| Date | 2011-08-15 19:25 +0100 |
| Message-ID | <pan.2011.08.15.18.25.07.960000@nowhere.com> |
| In reply to | #8861 |
On Mon, 15 Aug 2011 13:33:45 +0000, Juha Nieminen wrote: > va_list is part of the C89 standard, yet you claim there is no portable > way. Read the original question: > But I also have functions with variable arguments like this: > extern int function2(int, ...) > > So how can I write my own function which calls that? To which, the answer is "there is no portable solution". If the OP was writing the function, he could just write a va_list based version. But if all he has is a variadic function, there's no portable way to "wrap" it (i.e. write a function which is itself variadic and which passes those arguments down to the original function).
[toc] | [prev] | [next] | [standalone]
| From | Juha Nieminen <nospam@thanks.invalid> |
|---|---|
| Date | 2011-08-16 07:36 +0000 |
| Message-ID | <4e4a1e11$0$3070$7b1e8fa0@news.nbl.fi> |
| In reply to | #8871 |
Nobody <nobody@nowhere.com> wrote: > On Mon, 15 Aug 2011 13:33:45 +0000, Juha Nieminen wrote: > >> va_list is part of the C89 standard, yet you claim there is no portable >> way. > > Read the original question: > >> But I also have functions with variable arguments like this: >> extern int function2(int, ...) >> >> So how can I write my own function which calls that? > > To which, the answer is "there is no portable solution". If the OP was > writing the function, he could just write a va_list based version. But if > all he has is a variadic function, there's no portable way to "wrap" it > (i.e. write a function which is itself variadic and which passes those > arguments down to the original function). I see. I thought the original question was how to pass a variable number of arguments from one function (taking them) to another (also taking them), for which there is indeed a standard solution.
[toc] | [prev] | [next] | [standalone]
| From | "Alf P. Steinbach" <alf.p.steinbach:usenet@gmail.com> |
|---|---|
| Date | 2011-08-12 21:35 +0200 |
| Message-ID | <j23vaj$su5$1@dont-email.me> |
| In reply to | #8740 |
On 12.08.2011 20:58, Angus wrote:
>
> I need to put all functions calling into a C API into a separate
> source file unit. It is due to defines interfering with other code.
> So to keep the possibly interfering code separate.
>
> Anyway, most functions are eg int function2(int) so I just implement
> in separate file like this:
> int XXfunction1(int val) { return function(val) }
>
> But I also have functions with variable arguments like this: extern
> int function2(int, ...)
>
> So how can I write my own function which calls that?
>
> This doesn't seem to work:
> int XXFunction2(int val, ...) {
> return function2(val, ...);
> }
>
> How do I write the function?
In some cases, such as with printf family, you can find variants that
accept va_list. Then just use the standard library's macros.
Otherwise, you need to find a way to express a general call as a
sequence of calls with known arguments. That depends entirely on the
function. Maybe you need to single out the important use-cases.
The way standard iostreams do this can serve as main example of a
reasonable way to do it, but iostreams rely on the fact that arguments
are processed in sequence, which your function may not necessarily do.
Cheers & hth.,
- Alf
[toc] | [prev] | [standalone]
Back to top | Article view | comp.lang.c++
csiph-web