473,406 Members | 2,377 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

Portable?

Hiya,

Quick question:

/* test.c, compile with gcc -ansi -pedantic -Wall test.c -o test */

int foo(int a, int b, int c, int d) { return 0; }
int bar(int a, int b, int c, int d) { return 1; }

int main(void)
{
int a = 1;

a = (a ? foo : bar)(0, 1, 2, 3);

return a;
}

Looks conforming to me [the (a ? foo : bar)] ... right?

Cheers,
Gibby Koldenhof
Nov 14 '05 #1
2 1121
"Gibby Koldenhof" <flux@__*********@nebule.com> wrote in message
news:42**********************@news.wanadoo.nl...
Hiya,

Quick question:

/* test.c, compile with gcc -ansi -pedantic -Wall test.c -o test */

int foo(int a, int b, int c, int d) { return 0; }
int bar(int a, int b, int c, int d) { return 1; }

int main(void)
{
int a = 1;

a = (a ? foo : bar)(0, 1, 2, 3);

return a;
}

Looks conforming to me [the (a ? foo : bar)] ... right?

Cheers,
Gibby Koldenhof


Yes, I think this is OK, C is beautifull.

I know this is not:

(a ? foo : bar) = NULL;
Nov 14 '05 #2
Gibby Koldenhof wrote:
/* test.c, compile with gcc -ansi -pedantic -Wall test.c -o test */

int foo(int a, int b, int c, int d) { return 0; }
int bar(int a, int b, int c, int d) { return 1; }

int main(void)
{
int a = 1;

a = (a ? foo : bar)(0, 1, 2, 3);

return a;
}

Looks conforming to me [the (a ? foo : bar)] ... right?


It's 'conforming', but that doesn't mean much! More importantly,
it is 'strictly conforming'. Although, without any output, this
is often true of programs which would otherwise only be
'conforming'.

But in answer to your real question, you can portably use
(compatible) function pointers as operands to the conditional
operator.

--
Peter

Nov 14 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

13
by: James Harris | last post by:
Hi, Can someone recommend a book that will teach me how to approach C programming so that code is modularised, will compile for different environments (such as variations of Unix and Windows),...
22
by: SeeBelow | last post by:
Is there any way, in C, of interacting with a running program, but still using code that is portable, at least between linux and Windows? By "interacting" it could be something as simple as...
10
by: Jason Curl | last post by:
Dear C group, I'm very interested in writing portable C, but I only have GNU, Sparc and Cygwin to compile on. What I find is the biggest problem to writing portable C is what headers to...
8
by: suresh_C# | last post by:
Dear All, What is difference between Portable Executable (PE) file and a Assembly? Thanks, Mahesh
2
by: Tull Clancey | last post by:
Hi all. I'm nearing completion of a host app that needs to send data to, and receive data back from a portable, an HP device. The application running on the portable will be a .net application....
131
by: pemo | last post by:
Is C really portable? And, apologies, but this is possibly a little OT? In c.l.c we often see 'not portable' comments, but I wonder just how portable C apps really are. I don't write...
162
by: Richard Heathfield | last post by:
I found something interesting on the Web today, purely by chance. It would be funny if it weren't so sad. Or sad if it weren't so funny. I'm not sure which. ...
409
by: jacob navia | last post by:
I am trying to compile as much code in 64 bit mode as possible to test the 64 bit version of lcc-win. The problem appears now that size_t is now 64 bits. Fine. It has to be since there are...
10
by: bramnizzle | last post by:
I don't know if this is the right thread or not, but... In my endless pursuit to hold on to my dinosaur laptop (Dell 1100 Inspiron - circa 2004)...I want to keep as much space free for my...
23
by: asit | last post by:
what is the difference between portable C, posix C and windows C ???
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.