473,569 Members | 2,489 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Translating from C with extensions to standard C

There are several compilers which accept various
extensions to the C language and produce native
code. But I wonder if there are any which offer the
option to translate from C with some extensions
to standard C.

Nov 19 '06 #1
16 1532

Spiros Bousbouras wrote:
There are several compilers which accept various
extensions to the C language and produce native
code. But I wonder if there are any which offer the
option to translate from C with some extensions
to standard C.
I am afraid not. The reason why they extend C is mainly that standard C
can't do the things that they want. Standard C is aimed at portability
while extended C is aimed at optimizing for low level operations or for
certain architecture.
Maybe few extensions can be translated, but most not.

Nov 19 '06 #2
Cong Wang wrote:
Spiros Bousbouras wrote:
There are several compilers which accept various
extensions to the C language and produce native
code. But I wonder if there are any which offer the
option to translate from C with some extensions
to standard C.

I am afraid not. The reason why they extend C is mainly that standard C
can't do the things that they want. Standard C is aimed at portability
while extended C is aimed at optimizing for low level operations or for
certain architecture.
Maybe few extensions can be translated, but most not.
Can you give me an example of an extension which
cannot be translated into (efficient) standard C ?

Nov 19 '06 #3

Spiros Bousbouras wrote:
Cong Wang wrote:
Spiros Bousbouras wrote:
There are several compilers which accept various
extensions to the C language and produce native
code. But I wonder if there are any which offer the
option to translate from C with some extensions
to standard C.
I am afraid not. The reason why they extend C is mainly that standard C
can't do the things that they want. Standard C is aimed at portability
while extended C is aimed at optimizing for low level operations or for
certain architecture.
Maybe few extensions can be translated, but most not.

Can you give me an example of an extension which
cannot be translated into (efficient) standard C ?
Of course. The following code is from Linux kernel and is written with
GCC extensions:

#define typecheck(type, x) \
({ type __dummy; \
typeof(x) __dummy2; \
(void)(&__dummy == &__dummy2); \
1; \
})

It can hardly be translated into standard C.
And another obvious extension of GCC that can't be translated is inline
asm, of course.

Nov 19 '06 #4
Spiros Bousbouras said:
There are several compilers which accept various
extensions to the C language and produce native
code. But I wonder if there are any which offer the
option to translate from C with some extensions
to standard C.
The reason that programmers sometimes use extensions is that the standard
language doesn't provide a way to do what they need to do. In other words,
the answer is no, there are no compilers which genuinely offer this option
in the general case.

--
Richard Heathfield
"Usenet is a strange place" - dmr 29/7/1999
http://www.cpax.org.uk
email: normal service will be restored as soon as possible. Please do not
adjust your email clients.
Nov 19 '06 #5
Spiros Bousbouras wrote:
Cong Wang wrote:
>>Spiros Bousbouras wrote:
>>>There are several compilers which accept various
extensions to the C language and produce native
code. But I wonder if there are any which offer the
option to translate from C with some extensions
to standard C.

I am afraid not. The reason why they extend C is mainly that standard C
can't do the things that they want. Standard C is aimed at portability
while extended C is aimed at optimizing for low level operations or for
certain architecture.
Maybe few extensions can be translated, but most not.


Can you give me an example of an extension which
cannot be translated into (efficient) standard C ?
Packed data structures and special interrupt function types spring to mind.

--
Ian Collins.
Nov 19 '06 #6
"Cong Wang" <xi************ @gmail.comwrite s:
Spiros Bousbouras wrote:
[...]
>Can you give me an example of an extension which
cannot be translated into (efficient) standard C ?

Of course. The following code is from Linux kernel and is written with
GCC extensions:

#define typecheck(type, x) \
({ type __dummy; \
typeof(x) __dummy2; \
(void)(&__dummy == &__dummy2); \
1; \
})

It can hardly be translated into standard C.
And another obvious extension of GCC that can't be translated is inline
asm, of course.
That specific construct can't be expressed in standard C, but any
program that uses it can be translated into an equivalent standard C
program. The extended-C to C translator would just have to replace
"typeof(x)" with the actual type of x.

There's precedent for this kind of thing; see cfront.
And another obvious extension of GCC that can't be translated is inline
asm, of course.
That's a better example. (I suppose a translator could emit standard
C code for a CPU emulator, but that's probably cheating.)

--
Keith Thompson (The_Other_Keit h) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <* <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
Nov 19 '06 #7
Spiros Bousbouras wrote:
Cong Wang wrote:
>Spiros Bousbouras wrote:
>>There are several compilers which accept various extensions to
the C language and produce native code. But I wonder if there
are any which offer the option to translate from C with some
extensions to standard C.

I am afraid not. The reason why they extend C is mainly that
standard C can't do the things that they want. Standard C is
aimed at portability while extended C is aimed at optimizing for
low level operations or for certain architecture.
Maybe few extensions can be translated, but most not.

Can you give me an example of an extension which
cannot be translated into (efficient) standard C ?
You don't even have to go to extensions. Both offsetof() and
getc() are not translatable. That's why they are part of the
standard library.

--
Chuck F (cbfalconer at maineline dot net)
Available for consulting/temporary embedded and systems.
<http://cbfalconer.home .att.net>
Nov 19 '06 #8

CBFalconer wrote:
Spiros Bousbouras wrote:
Cong Wang wrote:
Spiros Bousbouras wrote:

There are several compilers which accept various extensions to
the C language and produce native code. But I wonder if there
are any which offer the option to translate from C with some
extensions to standard C.

I am afraid not. The reason why they extend C is mainly that
standard C can't do the things that they want. Standard C is
aimed at portability while extended C is aimed at optimizing for
low level operations or for certain architecture.
Maybe few extensions can be translated, but most not.
Can you give me an example of an extension which
cannot be translated into (efficient) standard C ?

You don't even have to go to extensions. Both offsetof() and
getc() are not translatable. That's why they are part of the
standard library.
Is offsetof() not translatable?

#ifndef offsetof
#define offsetof(p_type ,field) ((size_t)&(((p_ type *)0)->field))
#endif

Nov 19 '06 #9
In article <v7************ *************** ***@bt.com>,
Richard Heathfield <in*****@invali d.invalidwrote:
>Spiros Bousbouras said:
>There are several compilers which accept various
extensions to the C language and produce native
code. But I wonder if there are any which offer the
option to translate from C with some extensions
to standard C.

The reason that programmers sometimes use extensions is that the standard
language doesn't provide a way to do what they need to do. In other words,
the answer is no, there are no compilers which genuinely offer this option
in the general case.
If there were (i.e., if it [the 'it' that is the subject of this thread]
was possible), this ng would be a lot more interesting.

Everytime somebody posted something off-topic (say, something Linux-y or
Windows-y), we could give him the Standard C version of it, and
everybody would live happily everafter.

Nov 19 '06 #10

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

Similar topics

30
1991
by: Jive | last post by:
Can someone explain to me why Python 2.4 on MS Windows has these backward compatibility problems? What am I missing? Why won't extensions compiled to run with 2.3 also work with 2.4? Why does it matter whether a component was compiled with VC++ 6.0 or 7.1? I've been using MS stuff for 6 years. Before I started using Python, I don't...
2
2316
by: Don Robertson | last post by:
Greetings, I need to be able to output text with some characters escaped - eg change a &#xA; to \n I am at a loss as how to do this. I am trying translate($text,'&#xA;','\n') and
2
1291
by: BCC | last post by:
Hi, I have a need to read in a very simple xml file and initialized some objects from the data. I was reading on the ms website that .net contains its own XML parser, and it sounds pretty good for what I need. However, to use the code, it looks like I need to compile with managed extensions. Since my project does not use managed...
2
1420
by: Roderick Bloem | last post by:
I am going to take the liberty of crossposting this to comp.lang.c++ (originally comp.lang.c), and to summarize the discussion for the sake of those reading only c++. The question is: If you are writing C and you have a struct P, can you create a struct C that is an extension of the first (starts just like P and adds some data), and then...
27
2947
by: jacob navia | last post by:
Has anyone here any information about how arrays can be formatted with printf? I mean something besides the usual formatting of each element in a loop. I remember that Trio printf had some extensions but I do not recall exactly if they were meant for arrays. Thanks
4
1231
by: J | last post by:
I've just been reading a few articles on how Managed Extensions are now obsolete! Tough thing to hear, as I've been spending every spare moment studying them to try to solve a problem. I'd like to get up to speed on this as quickly as possible, and find out how the new CLI approach relates to my current app (will it fix anything? Make...
3
7475
by: Chris Paul | last post by:
I'm having trouble with PHP & PostgreSQL/OpenLDAP/Apache on Windows. I've set this up countless times on BSD (piece of cake) but I'm trying to do this on Windows now so that my developer can work on her local machine. Everything looks pretty good. OpenLDAP/cygwin works great. PostgreSQL works great. Apache runs. PHP runs. But when I...
2
1625
by: kimi | last post by:
Voip Learning and Translating Tutorial Voice Over IP is a new communication means that let you telephone with Internet at almost null cost. How this is possible, what systems are used, what is the standard, all that is covered by this Howto. http://www.freewebs.com/voipformula/VoIP-HOWTO.html
59
4187
by: Anando | last post by:
Hi, I have a linear singly linked list of 100 elements. I would like to prune it such that only user specified elements (say only the elements 1, 13, 78 and 100 of the original list) survive after pruning. Can somebody show me how to do this ? I am a scientist and not a computer engineer/student. This will help me develop an application...
0
8132
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...
1
7678
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
6286
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...
1
5514
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...
0
5222
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3656
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3644
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1226
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
944
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...

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.