473,698 Members | 2,141 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

This is ridiculous!

#include <string>
#include <iostream>
using std::cout;
using std::endl;

void FunctionThatMod ifies(std::stri ng &a)
{
a = "You've been modified.";
}
int main()
{
std::string const a("Untouchable. ");
std::string &b = a; //Actually compiles with error!
FunctionThatMod ifies(b);
std::cout << b;
}
Compiler gives me a warning. I think it should give me a downright error,
and I want it to give me a downright error.

Firstly, does the Standard say whether this should generate a warning or
an error?

Secondly, do compilers have an option whereby you can make it give an
error? If so, I'll be using it.
-Tomás
Mar 4 '06
50 2716
Kaz Kylheku wrote:
Old Wolf wrote:
IMHO the standard ought to
say that the diagnostic itself contain a clue as to whether
it is one that's required by the standard, or whether it is
something specific to that implementation. (eg. [E] for
required diagnostics and [W] for others).
The users and implementors should decide whether they need such a
feature.


Well, most implementers only implement things that lead to their
financial gain. Nobody is going to buy a compiler because it has
nice error messages and I'm sure they have better things (eg.
C99 compliance) to work on.
As a user, you should know the language well enough to know what is a
required diagnostic and what is not.
90% of people don't, as evinced by this newsgroup!
IMHO the compiler should have well-designed interaction with
its user -- novice users and experienced users alike.
As an implementor, by distinguishing required diagnostics from the
superfluous ones, you are only helping the user write code that will be
portable to competitive compilers.
That's drawing a long bow!
You are also being forced to separate the messages into two obvious
classes, which gives users a kind of license to ignore any of the
lesser ones that are not marked [E]. Implementors should be allowed to
decide what diagnostics are important.
As long as there is a switch for standard-compliant mode (be it
the default or not), I'd be happy.
Then there is the problem that there are errors which do not require
diagnostics. If the impelmentation finds undefined behavior, a
legitimate response is to stop translating the program. A [W]
diagnostic would not be appropriate for that situation.
Why not? Often the standard lists things as UB, but the compiler
finds it can do what the user intended. I think it's ideal that in case
the compiler translates the program and issues a warning that
the code might not work on other compilers.
This still sucks because some undefined behaviors are hard to analyze
for accurately. The analysis becomes a lot easier and cheaper if the
result does not have to be conclusive, but only come up with a
suspicion that something is wrong.


You don't have to diagnose UB. Of course it'd be helpful if
compilers did diagnose a bit more of it; eg. GCC 4 does
report when you violate the sequence point rules.

Mar 13 '06 #51

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

Similar topics

35
7753
by: Vamsi Mudrageda | last post by:
I am kind of new to Python, and after trying and using wxPython, I found it kind of lacking in easy-to-read documentation, speed at loading, and GUI response-time. So I am looking for an another GUI toolkit that is cross-platform for Python, and am leaning toward PyQt (PyGTK is kind of dull looking in comparison). Unfortunately, although TrollTech says Qt is cross-platform, its license strategy has me a bit confused. So here is to...
52
6309
by: Vladimir Grul | last post by:
Hello, I have a class member function declared as class some_class { .... virtual int call(void); }; Can I use this-> inside the function body?
4
2159
by: Schraalhans Keukenmeester | last post by:
I have no clue why below code (found it somewhere and altered it a wee bit to my needs) will run without problem in both IE and Mozilla FireFox 1.0 but in the latter it takes up close to 100% cpu. It does check for type of browser, and indeed all works fine apart from that ridiculous amount of cpu taken. If you want to see if it does so in your firefox/xp too, it's embedded in my homepage (www.westerterp.com) Can anyone explain why...
23
355
by: Darklight | last post by:
Question taken from a book Write a function that accepts two strings. Use the malloc() function to allocate enough memory to hold two strings after they have been concatenated(linked). Return a pointer to this new string. /* STRCAT1.C PROGRAM TO LINK TWO STRINGS TOGETHER */ #include<stdio.h> #include<string.h> #include<stdlib.h>
6
1443
by: RichG | last post by:
Does anyone remember this: Set datapath to "c:\somewhere" dNetUse "SomeTable" do some db work I asked the question a couple of days ago about how to attach a recordset or some form of data to a datagrid. I was using DAO. The lack of responses seemed to indicate that the question was out of the range of an answer. So I started looking around to find out what does this datagrid want that the datagrid in VB5 did not need. It looked...
171
4875
by: Raman | last post by:
Hi All, Here is a small Code, int main(void) { char *p=(char *) malloc(100); strcpy(p,"Test1234567890"); p=p+10; free(p);
30
508
by: Bill Reid | last post by:
#define MAX_VALUES 64 typedef struct { unsigned value_1; double value_2; double value_3; double value_4; } VALUES; typedef struct {
26
2839
by: Tomás Ó hÉilidhe | last post by:
Has anyone here got access to a ridiculous computer? Something like: CHAR_BIT == 9 PADDING_BITS(int) != 0 NUMBER_SYSTEM == SIGN_MAGNITUDE Null pointer bit pattern == All ones I'm writing some fully-portable code and would love to actually compile it for, and test it on, a very strange machine :-D
40
1986
by: Dave | last post by:
Hello, I'm teaching myself C by working my way through Steve Summit's tutorial (http://www.eskimo.com/~scs/cclass/cclass.html). In one of the questions (assignment 6, exercise 7), you have to write a function to read lines of arbitrary length from the command line, using malloc() and realloc() to allocate the necessary memory to hold the lines. I came up with this: char *getline(char *line) {
0
8673
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
8601
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
9156
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
9021
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
8892
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
7716
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
6518
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
4365
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...
3
1998
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.