It seems to me that the Visual Studio C compiler (both 6.0 and 2003),
which claims ANSI/ISO conformance, has a nasty bug involving sizes of
pointers to arrays.
The following code:
#include <stdio.h>
int main(void)
{
int a[10];
int (*p)[10];
printf("%lu\n", (unsigned long) sizeof &a);
printf("%lu\n", (unsigned long) sizeof p);
return 0;
}
compiled with the "disable extensions" flag, produces this output:
40
4
I'm pretty sure that a conforming compiler should produce a program
which prints the same number two times, since &a and p are of the same
type. Right?
--
Enrico `Trippo' Porreca 5 1223
Enrico `Trippo' Porreca <ep******@people.it> scribbled the following: It seems to me that the Visual Studio C compiler (both 6.0 and 2003), which claims ANSI/ISO conformance, has a nasty bug involving sizes of pointers to arrays.
The following code:
#include <stdio.h>
int main(void) { int a[10]; int (*p)[10];
printf("%lu\n", (unsigned long) sizeof &a); printf("%lu\n", (unsigned long) sizeof p); return 0; }
compiled with the "disable extensions" flag, produces this output:
40 4
I'm pretty sure that a conforming compiler should produce a program which prints the same number two times, since &a and p are of the same type. Right?
Yes, I think there is something wrong here. sizeof a should be 10 *
sizeof(int), which is most likely 40 on your system, but sizeof &a
should be identical to sizeof(int(*)[10]), which is equivalent to
sizeof p.
I tried it on gcc on my Linux system and it printed 4 for both.
--
/-- Joona Palaste (pa*****@cc.helsinki.fi) ------------- Finland --------\
\-- http://www.helsinki.fi/~palaste --------------------- rules! --------/
"My absolute aspect is probably..."
- Mato Valtonen
Joona I Palaste wrote: Enrico `Trippo' Porreca <ep******@people.it> scribbled the following:
It seems to me that the Visual Studio C compiler (both 6.0 and 2003), which claims ANSI/ISO conformance, has a nasty bug involving sizes of pointers to arrays.
The following code:
#include <stdio.h>
int main(void) { int a[10]; int (*p)[10];
printf("%lu\n", (unsigned long) sizeof &a); printf("%lu\n", (unsigned long) sizeof p); return 0; }
compiled with the "disable extensions" flag, produces this output:
40 4
I'm pretty sure that a conforming compiler should produce a program which prints the same number two times, since &a and p are of the same type. Right?
Yes, I think there is something wrong here. sizeof a should be 10 * sizeof(int), which is most likely 40 on your system, but sizeof &a should be identical to sizeof(int(*)[10]), which is equivalent to sizeof p. I tried it on gcc on my Linux system and it printed 4 for both.
Yes, gcc prints it "right". We had a discussion on it.comp.lang.c about
the results of that code when compiled with Visual Studio, and I'm
wondering about an incapacity of cl to distinguish array_name from
&array_name (at least when one applies sizeof to them).
--
Enrico `Trippo' Porreca
In <40**************@people.it> Enrico `Trippo' Porreca <ep******@people.it> writes: It seems to me that the Visual Studio C compiler (both 6.0 and 2003), which claims ANSI/ISO conformance, has a nasty bug involving sizes of pointers to arrays.
The following code:
#include <stdio.h>
int main(void) { int a[10]; int (*p)[10];
printf("%lu\n", (unsigned long) sizeof &a); printf("%lu\n", (unsigned long) sizeof p); return 0; }
compiled with the "disable extensions" flag, produces this output:
40 4
I'm pretty sure that a conforming compiler should produce a program which prints the same number two times, since &a and p are of the same type. Right?
Right. The Microsoft compiler can't tell the difference between a and &a
in this context.
OTOH, I can't see this bug as having any relevance in real life code:
if you *really* need to know the size of a pointer to array, sizeof p is
the most natural way of obtaining it: i.e. you use an object of the right
type as the operand of sizeof, rather than an expression of the right
type. The usual counterexample is malloc calls, but they involve
expressions using the unary * operator:
int *p = malloc(10 * sizeof *p);
Dan
--
Dan Pop
DESY Zeuthen, RZ group
Email: Da*****@ifh.de This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Jeff Epler |
last post by:
Hello.
Recently, Generator Comprehensions were mentioned again on python-list.
I have written an implementation for the compiler module. To try it
out, however, you must be able to rebuild...
|
by: Bryan Parkoff |
last post by:
You may notice that switch (...) is much faster than function that can
gain a big improved performance because it only use JMP instruction however
function is required to use CALL, PUSH, and POP...
|
by: Bjorn |
last post by:
I'm using interfaces in C++ by declaring classes with only pure virtual
methods. If then someone wants to implement the interface they
needs to inherit from the class. If the implementing class...
|
by: Tao Wang |
last post by:
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Hi,
I saw cuj's conformance roundup, but the result is quite old. I think
many people like me want to know newer c++ standard conformance test...
|
by: joshc |
last post by:
I'm writing some C to be used in an embedded environment and the code
needs to be optimized. I have a question about optimizing compilers in
general. I'm using GCC for the workstation and Diab...
|
by: pj |
last post by:
(Was originally, probably wrongly, posted to the vc subgroup.)
(This doesn't appear to be a c# problem, but a problem with a bug in
the Visual Studio c# compiler, but, any help will be welcome...)...
|
by: rollasoc |
last post by:
Hi,
I seem to be getting a compiler error
Internal Compiler Error (0xc0000005 at address 535DB439): likely culprit is
'BIND'.
An internal error has occurred in the compiler. To work around...
|
by: Mark Rockman |
last post by:
------ Build started: Project: USDAver2, Configuration: Debug .NET ------
Preparing resources...
Updating references...
Performing main compilation...
error CS0583: Internal Compiler Error...
|
by: toton |
last post by:
Hi,
Anyone have a link to comparative study of different C++ compilers
and how much they conform to C++ language standard? Most of the big
platforms I know have GCC which well supports C++...
|
by: Miroslaw Makowiecki |
last post by:
Where can I download Comeau compiler as a trial version?
Thanks in advice.
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
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,...
|
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,...
|
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...
|
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,...
| |