473,765 Members | 2,028 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

help on type compatibility?

Ark
Hello NG,

My Lint and my compiler disagree on whether this is valid code:

typedef int test_t(char *);
typedef int contest_t(const char *);
extern contest_t somefunction;
test_t *mypointer = somefunction;

I think the assignment is clean in what it does, but who cares? - What's
the verdict of the standard? (Both C90 and C99 resolutions are greatly
appreciated.)

Thank you,
- Ark
Feb 24 '06
29 2932
[given cp as a variable of type "const char *" and p as one
of type "char *"]
On Fri, 24 Feb 2006 18:48:46 +0000, Chris Torek wrote:
There is a special rule for assignment ... so that you can
do "cp = p", but not "p = cp".

This special rule does *not* apply to other cases, so:

char **pp;
...
pp = &cp;

requires a diagnostic.

In article <pa************ *************** @bsb.me.uk>
Ben Bacarisse <be********@bsb .me.uk> wrote:I some ways the more surprising example is that:

const char * const *pcp;
pcp = pp;

also requires a diagnostic. Surprising because this way round no
"const"ness is being lost.


Indeed, and this "works right" in C++. I do not know why the C99
folks did not adopt the C++ "const" rules here.
--
In-Real-Life: Chris Torek, Wind River Systems
Salt Lake City, UT, USA (40°39.22'N, 111°50.29'W) +1 801 277 2603
email: forget about it http://web.torek.net/torek/index.html
Reading email is like searching for food in the garbage, thanks to spammers.
Feb 26 '06 #21
On 2006-02-24, pete <pf*****@mindsp ring.com> wrote:
mark wrote:

pete wrote:
> Ark wrote:
>
> > char * is unqualified pointer to char; const char * is unqualified
> > pointer to const char.
>
> No.


Yes.


Idiot.


I think you are mistaken.

const char * is a pointer to const characters.
Feb 26 '06 #22
In comp.std.c Chris Torek <no****@torek.n et> wrote:

Indeed, and this "works right" in C++. I do not know why the C99
folks did not adopt the C++ "const" rules here.


Because the C++ folks chose to describe their language in a way that
isn't compatible with the way the C language was described, making it
necessary to translate the rules rather than just copying them, and
because C99 added the "restrict" qualifier that wasn't handled by the
rules.

-Larry Jones

Some people just don't have inquisitive minds. -- Calvin
Feb 26 '06 #23
Richard G. Riley wrote:

On 2006-02-24, pete <pf*****@mindsp ring.com> wrote:
mark wrote:

pete wrote:
> Ark wrote:
>
> > char * is unqualified pointer to char; const char * is unqualified
> > pointer to const char.
>
> No.

Yes.
Idiot.


I think you are mistaken.


I think so too.
const char * is a pointer to const characters.


--
pete
Feb 26 '06 #24

pete wrote:
pete wrote:
typedef int test_t(char *);

test_t test1, test2;

int main(void)
{
test1("Hello");
test1("World");


I intended that last line to be test2("World")
but it doesn't make much difference.

--
pete


This is the first time I hear about "function type". Even in K&R, I
don't remember any mention of this term. Thanks, pete. I'll look for
more about this.

Feb 27 '06 #25
Aegis wrote:
'Is char * compatible with const char *?'

3.5.4.1 from one of its clauses, states:

"For two pointer types to be compatible, both
shall be identically qualified and both shall
be pointers to compatible types."

So their compatibility is predicated upon
whether or not they
1) point to compatible types
2) share the same qualifications

2 does not hold here, and therefore the types are not compatible.


Kuyper wrote: I don't follow that: neither pointer type is qualified, so item [2]
holds. Only the pointed-at types are differently qualified. The pointer
types themselves are both unqualified.


I agree.

Ark's code in question was:
typedef int test_t(char *s);
typedef int contest_t(const char *cs);
extern contest_t somefunction;
test_t *mypointer = somefunction; // A

[A] is an error, because it is attempting to remove the 'const'
from from a pointed-to parameter type.

On the other hand, this should work:
extern contest_t otherfunc;
contest_t myotherptr = otherfunc; // B

because [b] is adding a 'const' qualifier to a pointed-to parameter
type, which IIRC is okay. In other words, parameter s is
assignment-compatible to parameter cs, so function pointer
otherfunc should be assignable to myotherfunc without needing
an explicit cast. (But I could be wrong.)

-drt

Feb 28 '06 #26
"David R Tribble" <da***@tribble. com> writes:
Aegis wrote:
'Is char * compatible with const char *?'

3.5.4.1 from one of its clauses, states:

"For two pointer types to be compatible, both
shall be identically qualified and both shall
be pointers to compatible types."

So their compatibility is predicated upon
whether or not they
1) point to compatible types
2) share the same qualifications

2 does not hold here, and therefore the types are not compatible.


Kuyper wrote:
I don't follow that: neither pointer type is qualified, so item [2]
holds. Only the pointed-at types are differently qualified. The pointer
types themselves are both unqualified.


I agree.

Ark's code in question was:
typedef int test_t(char *s);
typedef int contest_t(const char *cs);
extern contest_t somefunction;
test_t *mypointer = somefunction; // A

[A] is an error, because it is attempting to remove the 'const'
from from a pointed-to parameter type.

On the other hand, this should work:
extern contest_t otherfunc;


I'm assuming you meant:

extern test_t otherfunc;
contest_t myotherptr = otherfunc; // B

because [b] is adding a 'const' qualifier to a pointed-to parameter
type, which IIRC is okay. In other words, parameter s is
assignment-compatible to parameter cs, so function pointer
otherfunc should be assignable to myotherfunc without needing
an explicit cast. (But I could be wrong.)


Yeah, unfortunately you're wrong.

For two types to be compatible, they must be identically
qualified. For /assignment/ purposes, a special exemption was made for
pointers to differently-qualified types, but those pointers
themselves--and indeed, the pointed-two types as well--are not
compatible.

-Micah
Feb 28 '06 #27
On 23 Feb 2006 20:56:01 -0800, "aegis" <ae***@mad.scie ntist.com>
wrote:

Ark wrote:
Hello NG,

My Lint and my compiler disagree on whether this is valid code:
int (*) (char*) assigned int (*) (const char *)
Part of one of the clauses of 3.5.4.3 states: <snip>

(they're not compatible)

Right. And thus a diagnostic is required, and as for all required
diagnostics what if anything happens after that is up to the
implementation. And this doesn't change between C90/99.

Note however that T* and cv-T* are required to have the same
representation and alignment which according to a nonnormative
footnote is "intended" to allow interchangeabil ity as arguments among
other cases. Although unlike signed-unsigned and char*-void* there is
not normative language for unprototyped and va_arg calls. Even so an
implementation would be quite perverse to break any of these.

- David.Thompson1 at worldnet.att.ne t
Mar 3 '06 #28
ku****@wizard.n et wrote:
... if a footnote claims that something is true which cannot be derived from
the normative text, that claim is simply false, and can therefore be ignored.


No, footnotes cannot be ignored. Go back and pay more heed to
what I said upthread -- when it comes to understanding the scope
of certain requirements such as in the specific case being
discussed, what the total "truth" consists of might not be
apparent until *after* you take the footnote into account.
Note that the main text requirement uses a term that is not
fully and completely defined within the main text, but the
footnote tries to explain what is meant by the term. If you
ignore the footnote, then you cannot understand what is meant.
Mar 3 '06 #29
Douglas A. Gwyn wrote:
ku****@wizard.n et wrote:
... if a footnote claims that something is true which cannot be derived from
the normative text, that claim is simply false, and can therefore be ignored.

I said that badly - it shouldn't be ignored - the discrepancy should be
fixed, either by changing the normative text, or by changing the
footnote; possibly both. However, the portions of the footnote that
can't be derived from the normative text can't be used to judge whether
or not an implementation conforms to the standard. That's what
"normative" means.
No, footnotes cannot be ignored. Go back and pay more heed to
what I said upthread -- when it comes to understanding the scope
of certain requirements such as in the specific case being
discussed, what the total "truth" consists of might not be
apparent until *after* you take the footnote into account.


It might not be apparant, but once you know that it was intended, it
must be possible to go back to the normative text and see that it does
indeed say what it didn't apparantly say.

I know that there are meta-standards; standards which specify how
standards are to be created, written, and interpreted. I am sure that
there's an ISO standard somewhere that defines precisely what
"normative" means in the context of an ISO standard. I don't have a
copy of that standard, so I'm not sure what it says about this. It's
quite possible that "normative" has a meaning in ISO standards that is
consistent with what you say. However, if so, it's another example of
specialized jargon with a meaning quite different from it's ordinary
English meaning, and I personally would have recommended that a
different word be used.

To say that a statement is "normative" means that it defines a norm
against which something is to be judged. In the context of the
standard, I'd expect that the thing which is being judged is
conformance with the standard. If non-normative text says that
something is true, that can't be derived from the normative text, then
conformance of a particular implementation to the standard can't be
judged by whether or not that statement is true about that particular
implementation.

As the standard itself informs us (in a non-normative section), the
non-normative text is for information only. Using it for such
judgements would be using it for something more than information. When
it contains anything other than information, when it establishes
requirements not deriveable from normative text, then it is false
information, and should be treated as such.

Mar 3 '06 #30

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

Similar topics

7
8695
by: Mike | last post by:
I've been trying for the past week to put a simple code together. I have done a LOT of searching, found scripts showing the functions I would like to use, however when I mix them it all goes wrong, somehow I always end up with error messages and functions not working right. Can someone please help me? I have a form, inside is 1 Text Field and 2 Password Fields. What I'm looking to do is: - Make sure password fields are equal - Set...
7
1984
by: Trvl Orm | last post by:
I am working with 2 frames, Left and Right and the main code is in the left frame, which has been attached. Can someone please help me with this code. I am new to JavaScript and can't figure it out. What needs to happen is this: On the left frame you should have a series of buttons, which when pushed makes things happen on the right frame.
8
3393
by: DKM | last post by:
Here are the source code files to a Java applet that utilizes LiveConnect to communicate with Javascript, and the HTML file. The thing works both in IE 6.0 and FireFox 1.4. but with some problems. IE crashes when one refreshes the page or leave the page. This happens only after calling the Java method more than once. It does not crash if the Java method is called just once and then the page is refreshed. FireFox does not crash at all...
5
3001
by: Craig Keightley | last post by:
Please help, i have attached my page which worksin IE but i cannnot get the drop down menu to fucntion in firefox. Any one have any ideas why? Many Thanks Craig <<<<<<<<<<<<<<CODE>>>>>>>>>>>>>>>> <html>
8
5479
by: baustin75 | last post by:
Posted: Mon Oct 03, 2005 1:41 pm Post subject: cannot mail() in ie only when debugging in php designer 2005 -------------------------------------------------------------------------------- Hello, I have a very simple problem but cannot seem to figure it out. I have a very simple php script that sends a test email to myself. When I debug it in PHP designer, it works with no problems, I get the test email. If
16
2455
by: Randy Yates | last post by:
I have an Access database that has been running fine on multiple platforms (Windows 2000, Windows XP, etc.) for several years. Recently, the database has begun to issue "Run-Time Error 2467" on one XP platform when certain forms are opened. Other forms result in a total application crash with the resulting "Bug Report" dialog sequence. The same forms within the same application run fine under Win2000. I'm wondering if this is due to...
1
3718
by: Rahul | last post by:
Hi Everybody I have some problem in my script. please help me. This is script file. I have one *.inq file. I want run this script in XML files. But this script errors shows . If u want i am attach this script files and inq files. I cant understand this error. Please suggest me. You can talk with my yahoo id b_sahoo1@yahoo.com. Now i am online. Plz....Plz..Plz...
2
1468
by: Serge Rielau | last post by:
Hi folks, My fellow team mates had some extra time on their hands so we decided to spice up DB2 with a grab-bag of compatibility features. We wouldn't mind help validating the semantics match.... So for those of you blessed or cursed with a competitive DBMS here is a list of what we've added: 1. ** DUAL Always works without prefixing a schema
7
2372
by: gubbachchi | last post by:
Hi all, In my application I need to display the data fetched from mysql database after the user selects date from javascript calender. I have written the code in which after the user selects the date from calender and clicks search button it will fetch data from database. But what I need is as soon the user clicks the date, it should fetch data for that date from database. How to do it. Here is the code I am using <html> <script...
0
9404
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
10164
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...
1
9959
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,...
1
7379
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
6649
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 into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5277
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...
0
5423
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3926
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
2806
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.