Hi,
I know that C90 and C9x (N869) doesn't allow to define an array of size 0.
int x[0]; /* constraint violation */
I was under the impression that this was possible in C99, due to the common
C90 practice:
struct a
{
int x;
char y[1];
};
that allows to build a linear structure with an array bigger than one,
struct a
{
int x;
char y[0];
};
char x[123];
struct a *p = (struct a*) x;
or is it just an extension of gcc?
Thanks to clarify my close-to-melt brain.
(we have 40°C in Paris, hopefully, I go to Ireland for holydays next Sunday)
--
-ed- em**********@noos.fr [remove YOURBRA before answering me]
The C-language FAQ: http://www.eskimo.com/~scs/C-faq/top.html
<blank line>
FAQ de f.c.l.c : http://www.isty-info.uvsq.fr/~rumeau/fclc/ 5 8790
Emmanuel Delahaye <em**********@noos.fr> wrote: Hi,
I know that C90 and C9x (N869) doesn't allow to define an array of size 0.
int x[0]; /* constraint violation */
I was under the impression that this was possible in C99, due to the common C90 practice:
struct a { int x; char y[1]; };
that allows to build a linear structure with an array bigger than one,
struct a { int x; char y[0]; };
No, the C99 flexible array member looks like:
struct a
{
int x;
char y[];
};
char x[123]; struct a *p = (struct a*) x;
You can't do that, x isn't necessarily correctly aligned for access as
"struct a".
struct a *p = malloc(123);
Thanks to clarify my close-to-melt brain. (we have 40?C in Paris, hopefully, I go to Ireland for holydays next Sunday)
Bah, we get 40C here every summer :)
- Kevin.
Emmanuel Delahaye <em**********@noos.fr> wrote in
news:Xn***************************@130.133.1.4: (we have 40?C in Paris, hopefully, I go to Ireland for holydays next Sunday)
Bah, we get 40C here every summer :)
With air conditionning, I guess. No such a thing here! Trust me, it's hell!
Good grief, how can you not have A/C? Do you have running water? :-) BTW,
what's the dew point? That's what really makes you uncomfortable.
--
- Mark ->
--
In <Xn***************************@130.133.1.4> Emmanuel Delahaye <em**********@noos.fr> writes: struct a { int x; char y[0]; };
char x[123]; struct a *p = (struct a*) x;
Remember what we keep telling the beginners? Casts are evil in C!
If you don't know what you're doing when casting a pointer, don't do it!
Yeah, all this applies to you, too! If the x array is not properly
aligned for a struct a access, the behaviour of the cast is undefined!
or is it just an extension of gcc?
Why not ask gcc itself?
fangorn:~/tmp 2321> cat test.c
struct a
{
int x;
char y[0];
};
fangorn:~/tmp 2322> gcc -c -std=c99 -pedantic test.c
test.c:4: warning: ISO C forbids zero-size array `y'
To make the struct definition correct for C99, drop the 0 (declare y as a
sizeless array). This is a "flexible array member" in the C99 lingo.
Dan
--
Dan Pop
DESY Zeuthen, RZ group
Email: Da*****@ifh.de
In <Xn**********************************@130.133.1. 4> "Mark A. Odell" <no****@embeddedfw.com> writes: Emmanuel Delahaye <em**********@noos.fr> wrote in news:Xn***************************@130.133.1.4:
(we have 40?C in Paris, hopefully, I go to Ireland for holydays next Sunday)
Bah, we get 40C here every summer :)
With air conditionning, I guess. No such a thing here! Trust me, it's hell!
Good grief, how can you not have A/C?
Only the servers and the tape robot in the machine room are considered
worthy of it ;-(
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: Noah Spitzer-Williams |
last post by:
Hello guys,
I would like to do something seemingly simple: find out if an
element in an array that is passed to my function exists.
I used to think I could just do: if (arr) ...
However, if...
|
by: jr |
last post by:
Sorry for this very dumb question, but I've clearly got a long way to go!
Can someone please help me pass an array into a function. Here's a starting
point.
void TheMainFunc()
{
// Body of...
|
by: ritchie |
last post by:
Hi all!
Still working on this program!
Just to recap, I am writing a program to sort an array with four
different sort algorythms.
I am having a little trouble at the moment though!
Now, I...
|
by: Gerald |
last post by:
I have a problem with an array of pointers.
In a program I'm writing, I have to read a file, containing thousands
of short lines. The content of another file will be compared against
each line...
|
by: Herrcho |
last post by:
in K&R Chapter 6.3
it mentions two methods to calculate NKEYS.
and points out the first one which is to terminate the list of
initializers with a null pointer, then loop along keytab until the...
| |
by: Wynand Winterbach |
last post by:
I think every C programmer can relate to the frustrations that malloc
allocated arrays bring. In particular, I've always found the fact that
the size of an array must be stored separately to be a...
|
by: simkn |
last post by:
Hello,
I'm writing a function that updates an array. That is, given an
array, change each element.
The trick is this: I can't change any elements until I've processed
the entire array. For...
|
by: manochavishal |
last post by:
Hi,
I have a question.
How can i know the size of array when it is passed to a function.
For Example i have this code:
#include <stdio.h>
#include <stdlib.h>
|
by: Cyn |
last post by:
Hi,
I want to create a general array structure which can hold all types.
Something like this:
struct ARRAY
{
void **array;
size_t size;
};
|
by: Nepomuk |
last post by:
Hi!
I've read, that in C++ there's no predefined method, to calculate the size of an array. However, it's supposed to work withsizeof(array)/sizeof(array)Now, this does work in some situations, but...
|
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: 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...
|
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...
|
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,...
|
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...
|
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...
| |
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |