[Newbie] default bool value in C

  • Thread starter =?ISO-8859-1?Q?Une_b=E9vue?=
  • Start date
?

=?ISO-8859-1?Q?Une_b=E9vue?=

i's like having a function saying "my_func" with 1 or 2 args :

VALUE my_func(VALUE target_path, VALUE my_bool)

or if "my_bool" not given :

VALUE my_func(VALUE target_path)

stating in that case mybool = true;

is that possible in C ?
 
J

jacob navia

Une said:
i's like having a function saying "my_func" with 1 or 2 args :

VALUE my_func(VALUE target_path, VALUE my_bool)

or if "my_bool" not given :

VALUE my_func(VALUE target_path)

stating in that case mybool = true;

is that possible in C ?

This is not possible in standard C.

It is possible with the lcc-win32 C compiler and it is an extension to
C, i.e. "default function arguments". This extension is supported also
by the Pelles C compiler and (obviously) by all C++ compilers.

You would declare the function:

VALUE my_func(VALUE target_path,VALUE mybool=true);


Other C compilers do not implement this extension, as far
as I know.
 
?

=?ISO-8859-1?Q?Une_b=E9vue?=

jacob navia said:
This is not possible in standard C.

It is possible with the lcc-win32 C compiler and it is an extension to
C, i.e. "default function arguments". This extension is supported also
by the Pelles C compiler and (obviously) by all C++ compilers.

You would declare the function:

VALUE my_func(VALUE target_path,VALUE mybool=true);


Other C compilers do not implement this extension, as far
as I know.

OK thanks for your quick and clear answer.
I'm running under Mac OS X 10.4.7 aun using gcc :
gcc --version
powerpc-apple-darwin8-gcc-4.0.1 (GCC) 4.0.1 (Apple Computer, Inc. build
5363)
Copyright (C) 2005 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is
NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE.

as you've said :
You would declare the function:

VALUE my_func(VALUE target_path,VALUE mybool=true);

i could do a simple test for that, to get the answer on my platform ?
would that be a valid test (ie no compile error) ?
 
J

jaysome

This is not possible in standard C.

Enough said.
It is possible with the lcc-win32 C compiler and it is an extension to
C, i.e. "default function arguments". This extension is supported also
by the Pelles C compiler and (obviously) by all C++ compilers.

You would declare the function:

VALUE my_func(VALUE target_path,VALUE mybool=true);


Other C compilers do not implement this extension, as far
as I know.

So what? This newsgroup deals with code that conforms to the C
Standard, whether it be C90 or C99. Compiler extensions, which are by
definition non-standard, are off-topic here.
 
R

Richard Heathfield

jacob navia said:
Une bévue wrote:

This is not possible in standard C.
Correct.

It is possible with the lcc-win32 C compiler

No, it isn't.
 
C

Clark S. Cox III

Une said:
i's like having a function saying "my_func" with 1 or 2 args :

VALUE my_func(VALUE target_path, VALUE my_bool)

or if "my_bool" not given :

VALUE my_func(VALUE target_path)

stating in that case mybool = true;

is that possible in C ?

No. That is a feature of C++, but not C.
 
M

Mark McIntyre

This is not possible in standard C.

OK thanks for your quick and clear answer.
I'm running under Mac OS X 10.4.7 aun using gcc :[/QUOTE]

This is fine. but honestly, if you need C++ features, use C++, not C.
i could do a simple test for that, to get the answer on my platform ?

You could do it, but your code would be completely nonportable.
would that be a valid test (ie no compile error) ?

No, no error doesn't make a valid test. Compilers have no duty to
report every mistake as an error.


--
Mark McIntyre

"Debugging is twice as hard as writing the code in the first place.
Therefore, if you write the code as cleverly as possible, you are,
by definition, not smart enough to debug it."
--Brian Kernighan
 
?

=?ISO-8859-1?Q?Une_b=E9vue?=

Mark McIntyre said:
This is fine. but honestly, if you need C++ features, use C++, not C.

thanxs for your reply.

i can'r use C++ because i'm writting a C extension to Ruby being itself
written in C.

In fact because Ruby is written in C it has also mechanisms defined in
ruby.h able to solve the prob of default value, it's ok for that point
right now.
 
C

Clark S. Cox III

Une said:
thanxs for your reply.

i can'r use C++ because i'm writting a C extension to Ruby being itself
written in C.

[psuedo-OT]
Note that just because something needs to be callable from C doesn't
mean that it has to be written in C. Every single platform that I've
ever seen that has both a C and C++ implementation allows code written
in one language to call code written in the other (And that most
certainly includes MacOS).
[/psuedo-OT]
 
?

=?ISO-8859-1?Q?Une_b=E9vue?=

Clark S. Cox III said:
[psuedo-OT]
Note that just because something needs to be callable from C doesn't
mean that it has to be written in C. Every single platform that I've
ever seen that has both a C and C++ implementation allows code written
in one language to call code written in the other (And that most
certainly includes MacOS).
[/psuedo-OT]

that's OK but in the the case of a C extension to Ruby i do have a
ruby.h with a lib extending c itself to let C extension to Ruby easier
to write...

i'd had the choice of a prog language belonging to C i'd have choosen
ObjC, but even ObjC doesn't satisfy me from a ruby side usage point of
view )))
 

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

Similar Threads


Members online

Forum statistics

Threads
473,755
Messages
2,569,535
Members
45,007
Latest member
obedient dusk

Latest Threads

Top