473,799 Members | 3,053 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Is it a good thing that program mix C and C++?

Is it a good thing that program mix C and C++?

Mar 28 '07
45 2076
On 31 Mar, 07:29, Richard Heathfield <r...@see.sig.i nvalidwrote:
Malcolm McLean said:
I was converted to uncast malloc() by the ng. Not for the reason given
- that it can mask failure to include stdlib.h. In production code
that just can't happen.

When "just can't happen" relies on a basic level of human competence, we
can count on it happening at least 17 times a day, 260 days a year.
And 170 times a day the other 105.25 days. Emphasis on
"at least".

--
Bill Pursell

Mar 31 '07 #41
Kenny McCormack wrote:
[...]
The point is that is you consider the following three commonly harped on
things in this NG:

1) char a[10]; x = a[10];
2) void main()
3) char *x = (char *) malloc(10);

The first is clearly an error. The 2nd probably, and the third, really not.
Yet all three are harped upon with equal vigor, by a bunch of freaks who
don't understand the concept of degree.
However, there are times when a newbie mentions that the reason
for putting the cast on malloc in the first place was to stop the
compiler from complaining about the int-to-pointer conversion.

While one might argue that the forgotten include won't happen in
"production code", the audience for clc is much wider than those
who write C for a living.

Yes, the cast is "harmless" if you have the proper #include. But,
it appears to be a relatively common newbie error to forget the
necessary #include, and they learned somewhere that you can "shut
up" the compiler by adding the cast, rather than by fixing the
root cause of the problem.

Now, I have an excuse for casting the return at times -- I learned
C in pre-void days, when the cast was necessary. Those days are
long gone, but old habits are hard to break. (Just try typing the
word "print" without a "f" magically appearing after it.)

--
+-------------------------+--------------------+-----------------------+
| Kenneth J. Brody | www.hvcomputer.com | #include |
| kenbrody/at\spamcop.net | www.fptech.com | <std_disclaimer .h|
+-------------------------+--------------------+-----------------------+
Don't e-mail me at: <mailto:Th***** ********@gmail. com>

Apr 2 '07 #42
In article <46************ ***@spamcop.net >,
Kenneth Brody <ke******@spamc op.netwrote:
Those days are
long gone, but old habits are hard to break. (Just try typing the
word "print" without a "f" magically appearing after it.)
More than once, while writing English text, I've used the word "gets"
and then gone back to put an 'f' at the beginning.
dave

--
Dave Vandervies dj******@csclub .uwaterloo.ca
I try, and I'm just as quick to make a fool of myself as anybody.
Usually I don't make a complete fool of myself, but that happens too.
--Brendan Sechter in comp.lang.c
Apr 2 '07 #43
In article <11************ *********@p15g2 000hsd.googlegr oups.com>,
dolphin <jd*******@gmai l.comwrites
>Is it a good thing that program mix C and C++?
If you mean in the same file NO.

If you mean can you call other modules written in C from a C++ program
then that is OK. Many libraries are written in C

However you should not be compelling C in a C++ compiler

C++ is based on C90 and has diverged one way whilst C99 went a
different way.

--
\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\
\/\/\/\/\ Chris Hills Staffs England /\/\/\/\/
/\/\/ ch***@phaedsys. org www.phaedsys.org \/\/\
\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/

Apr 3 '07 #44
In article <11************ **********@p15g 2000hsd.googleg roups.com>,
user923005 <dc*****@connx. comwrites
>On Mar 27, 9:41 pm, "dolphin" <jdxyw2...@gmai l.comwrote:
>Is it a good thing that program mix C and C++?

The C++ language includes the standard C libraries. Un
Not yet it doesn't TR not with standing.

--
\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\
\/\/\/\/\ Chris Hills Staffs England /\/\/\/\/
/\/\/ ch***@phaedsys. org www.phaedsys.org \/\/\
\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/

Apr 3 '07 #45
On Mar 27, 11:41 pm, "dolphin" <jdxyw2...@gmai l.comwrote:
Is it a good thing that program mix C and C++?
You certainly do *not* want to mix C and C++ idioms in the same source
file (e.g., using new to allocate memory and free() to deallocate it),
but you can certainly have different source files written in different
languages; you just have to pay attention to linkage rules and
parameter passing conventions.

Apr 3 '07 #46

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

Similar topics

24
3617
by: matty | last post by:
Go away for a few days and you miss it all... A few opinions... Programming is a craft more than an art (software engineering, not black magic) and as such, is about writing code that works, first and foremost. If it works well, even better. The same goes for ease of maintenance, memory footprint, speed, etc, etc. Most of the time, people are writing code for a use in the *real world*, and not just as an academic exercise. Look at...
36
4657
by: toedipper | last post by:
Hello, I am designing a table of vehicle types, nothing special, just a list of unique vehicle types such as truck, lorry, bike, motor bike, plane, tractor etc etc For the table design I am proposing a single column table with a field name called vehicle_type and this will contain the vehicle type. Sot it will be
39
2864
by: Suresh | last post by:
Hi, I am new to C and curious to know some basic questions about C. Why C is good? In what way its better than any other languages? If it is no longer a choice of programming language...why people still study it? And also its not an OO language either...is there any advantages in being not an OO language? I know one reason is that, IT started with C and so they are still using
113
12359
by: Bonj | last post by:
I was in need of an encryption algorithm to the following requirements: 1) Must be capable of encrypting strings to a byte array, and decyrpting back again to the same string 2) Must have the same algorithm work with strings that may or may not be unicode 3) Number of bytes back must either be <= number of _TCHARs in * sizeof(_TCHAR), or the relation between output size and input size can be calculated simply. Has to take into account the...
13
2105
by: KV | last post by:
I'm new to OO Design, and I'm fixing to start writing my very first C# program. Given the complexity of OO programming, I would like to run something by this group and get general input. My example is a program called HijackThis. I'm sure many are familiar that it is a spyware removal tool. The program looks at over 20 places on Windows computers to see what is starting (with options to remove the offending software). The program can...
11
3810
by: Someonekicked | last post by:
I want to save tables of integers to files. One way to write the cells as fixed size in the file, is to use reinterpret_cast. Is that a bad choice, good choice? I remember once before I posted a program using it, and some suggested that I might get errors using it. are there any other ways to write the cells as fixed size in the file? (knowing the cells will only contain integers). here is how I plan to do it (without much caring...
63
3984
by: John Salerno | last post by:
I know there's a request for a good IDE at least once a week on the ng, but hopefully this question is a little different. I'm looking for suggestions for a good cross-platform text editor (which the features for coding, such as syntax highlighting, etc.) but not a full IDE with all the fancy jazz (GUI developer, UML diagrams, etc.). Ideally, it would be something I could even put on a flash drive and move from computer to computer, but...
6
1875
by: mast2as | last post by:
I have posted a few messages in the last few days about a project I am working on which is a quite simple parser. I ended up using the try/ catch structure as a general mechanism to control what's happening in the program when it finds a syntax error in the file it parses. I would like to know if this is 'an acceptable thing to do' from a programmation point of view, or if I should keep using it only for catch exception created withing the...
0
9685
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
9538
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
10473
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
10249
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...
1
10219
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,...
0
9068
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
7563
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
5461
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...
1
4138
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 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.