Hi,
I've been asked in a job interview how to make C code look like C++
code, and honestly I didn't know what to answer because I have never really
done a lot of C. Now, I've been searching around the web about web sites
that talk about this subject, but I've had no luck. Can anyone point me to
some web site about this subject? Thanks a lot! 16 2291
Fronsac wrote: Hi, I've been asked in a job interview how to make C code look like C++ code, and honestly I didn't know what to answer because I have never really done a lot of C. Now, I've been searching around the web about web sites that talk about this subject, but I've had no luck. Can anyone point me to some web site about this subject? Thanks a lot!
Making C code look like C++ generally requires making it actually be C++.
Why would you try to make one language only look like another? There's no
advantage, unless you're trying for the IOCCC.
In article <AL************ *********@wagne r.videotron.net >,
Fronsac <fr************ *@hotmail.com> wrote: Hi, I've been asked in a job interview how to make C code look like C++ code, and honestly I didn't know what to answer because I have never really done a lot of C. Now, I've been searching around the web about web sites that talk about this subject, but I've had no luck. Can anyone point me to some web site about this subject? Thanks a lot!
Answer #1: Why would you want to?
Answer #2: By writing bad C code
Answer #2b: By writing C code that looks like bad C++ code
Answer #3: By writing in the common subset of C and C++ (but see #1 and #2)
Answer #4: What are you really trying to find out?
One possibility is that they want C++-clean C code for a possible upgrade
path to C++. The correct solution to this is to use C++'s `extern "C"'
to allow C and C++ code to be linked together, and have C (compiled as
C) and C++ (compiled as C++) linked together when they want old (C)
code and new (C++) code in the same program. All that this requires
is that the header files used be both C-clean and C++-clean, which is
rather easier than the general case of all code.
Unless they're talking about all the angle brackets that C++ uses.
You might be able to get away with using the <: and :> digraphs for that.
dave
--
Dave Vandervies dj******@csclub .uwaterloo.ca[S]till not good enough for Richard Heathfield, but what can you do, really?
You could always write "only for clever people" on the cover.
--Ben Pfaff and Richard Heathfield in comp.lang.c
> Making C code look like C++ generally requires making it actually be C++. Why would you try to make one language only look like another? There's no advantage, unless you're trying for the IOCCC.
C++ is not always accessible on some platforms (think game consoles like the
old game boy might not have access to a C++ compiler), so you'll have to use
C and some tricks to have it behave like C++. From what I've gathered so
far, it's impossible with C syntax to achieve inheritence, though you can
fake it. For example :
struct Foo {
int var1;
}
struct Bar {
struct Foo base;
int var2;
}
Bar* createBar() {
return malloc( sizeof(Bar) );
}
void foo_incVar1( Foo* foo ) {
foo->var1++;
}
void bar_incVar2( Bar* bar ) {
bar->var2++;
/* though, you realize that if I want to access var1, I have to do
bar->base.var1, or ((Foo*)bar)->var1).
The thing that bugs me most though is that you can encapsulate your
data. */
}
void main() {
Foo* foo = (Foo*) createBar();
foo_incVar1( foo ); /* increments var1 */
bar_incVar2( (Bar*) foo ); /* increments var2 */
}
And you can use function pointers to simulate virtual methods for your
"objects".
"Fronsac" <fr************ *@hotmail.com> wrote: Hi, I've been asked in a job interview how to make C code look like C++ code, and honestly I didn't know what to answer because I have never really done a lot of C. Now, I've been searching around the web about web sites that talk about this subject, but I've had no luck. Can anyone point me to some web site about this subject? Thanks a lot!
You posted the same question with slightly different subject lines
to (at least) a.c.l.l.c-c++ and c.l.c.
If you feel the need to post to more than one news-group, please
cross-post rather than multi-post. Thank you.
BTW: C++ is off-topic in c.l.c.
Irrwahn,
change codepage to make english text look like chinese text.
--
Three is no spimle sbtsuuttie for cearful, cercrot,
wtlirtew-len Esglinh. Tehre is no slveir beullt.
(Rhacrid Hfiaehlted in c.p, 2003-09-25)
> Hi, I've been asked in a job interview how to make C code look like C++ code, and honestly I didn't know what to answer because I have never
really done a lot of C. Now, I've been searching around the web about web sites that talk about this subject, but I've had no luck. Can anyone point me to some web site about this subject? Thanks a lot!
Hi,
Do you mean you want to do object oriented programming in C? In that case,
there are many ways of doing this. The following article describes one way: http://www.accu.org/acornsig/public/articles/oop_c.html
Regards,
Nathan
> You posted the same question with slightly different subject lines to (at least) a.c.l.l.c-c++ and c.l.c.
Yeah, I was too lazy to copy-paste the subject line from the other post. I
posted in two forums just to be sure at least one person answered me. :)
If you feel the need to post to more than one news-group, please cross-post rather than multi-post. Thank you.
What is cross-post? Could you explain me what it is and how to do it? Thanks
a lot.
BTW: C++ is off-topic in c.l.c.
That's fine. I only asked here because I wanted to know more about a certain
way to code in C, and I thought here would be a great place to start.
Fronsac <fr************ *@hotmail.com> scribbled the following: If you feel the need to post to more than one news-group, please cross-post rather than multi-post. Thank you.
What is cross-post? Could you explain me what it is and how to do it? Thanks a lot.
Cross-posting is posting the same article to multiple newsgroups
simulatenously. Not identical copies of the article - the SAME article.
How to actually do this depends on your newsreader. All that is NEEDED
is that the NNTP headers have a "Newsgroups :" line consisting of
multiple newsgroup names (separated with commas), but not all
newsreaders allow you to edit NNTP headers directly. (tin, which I use
myself, does.)
Another way, and one recommended for Usenet beginners who don't yet
know how NNTP works, is to look around the "compose message" (or
similar) window and search for a text box labelled "Newsgroup" or
something. Then just type multiple group names (separated with commas)
there. Depending on your newsreader, it might or might not work. It
will work on most non-brain-dead newsreaders. (I count Microsoft
Outlook Express as non-brain-dead, but Google as brain-dead.)
--
/-- Joona Palaste (pa*****@cc.hel sinki.fi) ---------------------------\
| Kingpriest of "The Flying Lemon Tree" G++ FR FW+ M- #108 D+ ADA N+++|
| http://www.helsinki.fi/~palaste W++ B OP+ |
\----------------------------------------- Finland rules! ------------/
"You could take his life and..."
- Mirja Tolsa
"Nathan" <na************ @hotmail.com> wrote in message news:<bm******* ***@reader11.wx s.nl>... Hi, I've been asked in a job interview how to make C code look like C++ code, and honestly I didn't know what to answer because I have never really done a lot of C. Now, I've been searching around the web about web sites that talk about this subject, but I've had no luck. Can anyone point me to some web site about this subject? Thanks a lot!
Hi,
Do you mean you want to do object oriented programming in C? In that case, there are many ways of doing this. The following article describes one way: http://www.accu.org/acornsig/public/articles/oop_c.html
Or you can study the lightweight C++ preprocessor, which takes as input
a language that looks like C++ and produces good old C. http://students.ceid.upatras.gr/~sxanth/lwc/index.html
Next version has template specializations and other goodies.
"Fronsac" <fr************ *@hotmail.com> writes: I've been asked in a job interview how to make C code look like C++ code, and honestly I didn't know what to answer because I have never really done a lot of C. Now, I've been searching around the web about web sites that talk about this subject, but I've had no luck. Can anyone point me to some web site about this subject? Thanks a lot!
You could name all of your header files without .h suffixes.
--
"We put [the best] Assembler programmers in a little glass case in the hallway
near the Exit sign. The sign on the case says, `In case of optimization
problem, break glass.' Meanwhile, the problem solvers are busy doing their
work in languages most appropriate to the job at hand." --Richard Riehle This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Gabriel Mejía |
last post by:
Services or applications using ActiveX Data Objects (ADO) 2.0 or greater may
intermittently return empty recordsets on queries that should be returning
valid results. At the time the problem occurs, the same queries successfully
return the expected data when run from non-ADO sources, such as from ISQL in
Microsoft SQL Server. This problem predominantly occurs on multi-processor
computers but has also been known to occur on single-processor...
|
by: python |
last post by:
hello and thanks for reading this,
i have been a dos/windows user using some form of the basic language for 30 years now.
i own and run a small programming company and there is one feature that keeps me in the windows/basic world.
while i will agree that it has not evolved well, it does have one awesome feature that i have yet to see replicated in
any linux product that i know about so far.
i am a long time windows user and have had...
|
by: Alejandro Castañaza |
last post by:
Hi.
I'm writing a program, and I need to send confidential data through the
network, so I decided to use encryption, using the
System.Security.Cryptography namespace.
I'm using the sockets for the network communications, and the program first
does a key exchange, with the asymetric cipher classes, to get a new key for
the symmetric cipher. My problem is, that although I have checked that the
two points get to the same key and...
|
by: Daniel Thune, MCSE |
last post by:
I am having a problem with formatting a SOAP Header in a .Net client. The
client calls a Java Axis 1.1 based web service. In order to authenticate the
caller, the web service call is intercepted by another web service that
validates a security token in the header.
I have pasted my current SOAP message that my code sends as captured from a
trace function that I added. Below that is a sample SOAP message that the
developer of the web...
|
by: RSH |
last post by:
I am slowly getting the hang of objects and creating my own. I was given
some help in assigning an object to a ComboBox collection. I have been
looking at it and I get the concept which is very powerful but I'm having a
bit of a problem conceptually. I was hoping someone might be able to shed
some light on creating this object and assigning it in the manner. Also how
would I reference this object by name after it is created in this...
| |
by: seberino |
last post by:
Is there any advantage to a language having a nice mathematically
compact grammar like LISP does? (or at least used to?)
Many have admired the mathematically simple grammar of LISP
in which much of the language is built up from conses IIRC.
Python's grammar seems complicated by comparison.
Is this anything to worry about?
|
by: KShapiro |
last post by:
Hi All,
I am trying to assist my wife, by making a simple menu system for the website.
The web page is a .php4 file and does an include of the navigation file. Before it includes that file at the top I have the following line of code to include my .js file.
<script src="scripts/SideNav.js" language="JavaScript" type="text/javascript"></script>
that is inside the <head> tag. It used to work fine with a more hard coded version of...
|
by: tkondal |
last post by:
Hi all.
I just started looking at Python's ctypes lib and I am having trouble
using it for a function.
For starters, here's my Python code:
from ctypes import*;
myStringDLL= cdll.LoadLibrary("myStringDLL.dll");
|
by: jeddiki |
last post by:
Hi,
I am having difficulty seeing why my divs will not swap places :confused:
I want to swap the positions of the "Hot News" and the "Todays Bonuese" sections.
Here is how they look now:
http://www.expert-world.com/im/images/trash1.jpg
|
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,...
|
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...
| |
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 most users, this new feature is actually very convenient. If you want to control the update process,...
|
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
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...
|
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 the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
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
| |
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...
| |