473,748 Members | 9,641 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Making C better (by borrowing from C++)

I know that this topic may inflame the "C language Taleban", but is
there any prospect of some of the neat features of C++ getting
incorporated in C? No I am not talking out the OO stuff. I am talking
about the non-OO stuff, that seems to be handled much more elegantly in
C++, as compared to C. For example new & delete, references, consts,
declaring variables just before use etc.

I am asking this question with a vested interest. I would really like
to use these features in my C programs.

Masood

Nov 14 '05
85 3276
Chris Croughton wrote:
<cb********@yah oo.com> wrote:
jacob navia wrote:

All API functions under win32 use the _stdcall calling
convention. This means that the called function cleans up the
stack, i.e. adds to the stack before returning the space allocate
to make the argument frame. This means that all code for stack
adjustment is moved fom all call sites to the single instruction
in the called function.

This can't be done with functions that receive an unknown number
of arguments like printf, for instance.

In C you prototype those functions as
int myfn(char *,...);

It would be impossible for such functions to clean up the stack
since they can't know how much was pushed, they discover it at
run time, and it could be perfectly legal to pass more arguments
than needed.

It is needed then to have two disctinct calling conventions,
(there are more like fastcall where the arguments are passed in
registers but let's leave it at that).


Things like printf, and variadic functions in general, are NOT OS
calls (although they are a source of bugs). They are the creation
of the C library alone. If the C compiler has a different calling
protocol than the OS, then you simply need a collection of
interface functions to do the conversion. Those go in the library.


Thinking about it, it's quite possible for a compiler to use two
different calling conventions automatically. If it's a variadic
function, or (in C90) has a null prototype (), the calling code
pops the parameters, otherwise the called function pops them. If
a function has a fixed number of parameters (as anything using
_stdcall must do) this this is not a problem.

If there isn't a prototype in scope at the time of the function call,
assume whichever you like and issue a warning, it's te programmer's
problem...


As another ferexample, you can have a macro in stdio.h that reads:

#define printf _funnycall _xprintf

with whatever implementations specific action you wish from
_funnycall. _xprintf will be written to do the actual work. With
C99 variadic macros you can carry this further by including the
parameters to printf in xprintf.

--
"If you want to post a followup via groups.google.c om, don't use
the broken "Reply" link at the bottom of the article. Click on
"show options" at the top of the article, then click on the
"Reply" at the bottom of the article headers." - Keith Thompson
Nov 14 '05 #81
jacob navia <ja***@jacob.re mcomp.fr> wrote:
All API functions under win32 use the _stdcall calling convention.


They'd better not. I'm allowed to do this:

int func(void)
{
int _stdcall=4;
return _stdcall;
}

Oh, perhaps you meant to say that those functions _aren't ISO C_? Gosh,
what a surprise.

[ Snip rest of off-topic nonsense. ]

Richard
Nov 14 '05 #82
Richard Bos wrote:
jacob navia <ja***@jacob.re mcomp.fr> wrote:

All API functions under win32 use the _stdcall calling convention.

They'd better not. I'm allowed to do this:

int func(void)
{
int _stdcall=4;
return _stdcall;
}

Oh, perhaps you meant to say that those functions _aren't ISO C_? Gosh,
what a surprise.

[ Snip rest of off-topic nonsense. ]

Richard


Go tell that to Bill Gates Mr Boss.

[ Snip rest of off-topic nonsense. ]

You aren't able to argument anything anyway.
That would suppose making an intellectual effort and
try to explain your views.

Nov 14 '05 #83
On Mon, 21 Feb 2005 23:24:03 +0100, in comp.lang.c , jacob navia
<ja***@jacob.re mcomp.fr> wrote:
Richard Bos wrote:
jacob navia <ja***@jacob.re mcomp.fr> wrote:

All API functions under win32 use the _stdcall calling convention.


Oh, perhaps you meant to say that those functions _aren't ISO C_? Gosh,
what a surprise.

[ Snip rest of off-topic nonsense. ]

Go tell that to Bill Gates Mr Boss.


I'm trying to work out if you're being deliberately stupid, or merely
accidentally so. Are you trying to claim that Windows API calls are
standard C, or that somehow invoking Bill Gates' name will make them so, or
what?

--
Mark McIntyre
CLC FAQ <http://www.eskimo.com/~scs/C-faq/top.html>
CLC readme: <http://www.ungerhu.com/jxh/clc.welcome.txt >

----== Posted via Newsfeeds.Com - Unlimited-Uncensored-Secure Usenet News==----
http://www.newsfeeds.com The #1 Newsgroup Service in the World! 120,000+ Newsgroups
----= East and West-Coast Server Farms - Total Privacy via Encryption =----
Nov 14 '05 #84
jacob navia <ja***@jacob.re mcomp.fr> wrote:
Richard Bos wrote:
jacob navia <ja***@jacob.re mcomp.fr> wrote:

All API functions under win32 use the _stdcall calling convention.

They'd better not. I'm allowed to do this:

int func(void)
{
int _stdcall=4;
return _stdcall;
}

Oh, perhaps you meant to say that those functions _aren't ISO C_? Gosh,
what a surprise.

[ Snip rest of off-topic nonsense. ]

Richard


Go tell that to Bill Gates


Bill Gates doesn't post his non-conforming code to c.l.c.
Mr Boss.
Grow up...
[ Snip rest of off-topic nonsense. ]
....and get a brain. You didn't snip a single byte of my post.
You aren't able to argument anything anyway.
That would suppose making an intellectual effort and
try to explain your views.


I've done that in the past. And again, and again, and again. If you want
to review all my arguments for why "your" compiler is off-topic here, go
to DejaGoogle; I'm not going to rehash them yet another time. Every now
and then it still is a good idea to point out that your extensions are
off-topic in this newsgroup (and that you have a whole shining,
sparkling newsgroup for lcc to play around in), both for your own
edification and that of any lurkers; but if you haven't understood _why_
by now, you probably never will.

Richard
Nov 14 '05 #85
In article <42************ *********@news. wanadoo.fr>, jacob navia
<ja***@jacob.re mcomp.fr> writes
Richard Bos wrote:
jacob navia <ja***@jacob.re mcomp.fr> wrote:

All API functions under win32 use the _stdcall calling convention.

They'd better not. I'm allowed to do this:

int func(void)
{
int _stdcall=4;
return _stdcall;
}

Oh, perhaps you meant to say that those functions _aren't ISO C_? Gosh,
what a surprise.

[ Snip rest of off-topic nonsense. ]

Richard


Go tell that to Bill Gates Mr Boss.


Who cares what MS does? the majority of C programming is not for a
Windows target anyway.

Are you saying the MS does NOT produce a C compiler but something of
their own that does not conform to international standards?

/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\
\/\/\/\/\ Chris Hills Staffs England /\/\/\/\/\
/\/\/ ch***@phaedsys. org www.phaedsys.org \/\/
\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/
Nov 14 '05 #86

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

Similar topics

204
5020
by: Masood | last post by:
I know that this topic may inflame the "C language Taleban", but is there any prospect of some of the neat features of C++ getting incorporated in C? No I am not talking out the OO stuff. I am talking about the non-OO stuff, that seems to be handled much more elegantly in C++, as compared to C. For example new & delete, references, consts, declaring variables just before use etc. I am asking this question with a vested interest. I...
0
8989
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8828
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9537
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9367
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8241
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6795
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4869
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3309
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2213
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.