473,323 Members | 1,589 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,323 software developers and data experts.

Array managed by preprocessor

My teacher said that array in C is managed by preprocessor.

Preprocesser replace all array occurences (i.e. int a[10] ) with
something that I don't understand/remember well.

What's exactly happens with array during preprocessing/compiling stage?

Thanks in advance
Nov 14 '05 #1
18 2986
/* frank */ wrote:
My teacher said that array in C is managed by preprocessor.

Preprocesser replace all array occurences (i.e. int a[10] ) with
something that I don't understand/remember well.

What's exactly happens with array during preprocessing/compiling stage?

Thanks in advance


Well, there are two possibilities here:

1) You misunderstood what your teacher said.
2) Your teacher is horribly, horribly wrong.

I suspect you need to revisit the subject; why not *ask your teacher*?

HTH,
--ag

--
Artie Gold -- Austin, Texas

"What they accuse you of -- is what they have planned."
Nov 14 '05 #2
Artie Gold ha scritto:
1) You misunderstood what your teacher said.


If I have this array:

a[i]

the preprocessor translate it, into *(a+i)

a is translated as costant.
Thanks
Nov 14 '05 #3
/* frank */ <__*******@despammed.com> scribbled the following:
Artie Gold ha scritto:
1) You misunderstood what your teacher said.
If I have this array: a[i] the preprocessor translate it, into *(a+i) a is translated as costant.


The preprocessor doesn't translate it into anything. Its job is done at
that stage and it has exited stage left. [] is a full-blown operator in
C. Its behaviour is defined as the * (indirection) and + (addition)
operators combined so that a[i] means *(a+i). Also, i[a] means the same
thing as a[i].

--
/-- Joona Palaste (pa*****@cc.helsinki.fi) ------------- Finland --------\
\-- http://www.helsinki.fi/~palaste --------------------- rules! --------/
"A bicycle cannot stand up by itself because it's two-tyred."
- Sky Text
Nov 14 '05 #4
In 'comp.lang.c', /* frank */ <__*******@despammed.com> wrote:
My teacher said that array in C is managed by preprocessor.


Get a better teacher, and read your C-book about arrays. Do exercices.

--
-ed- get my email here: http://marreduspam.com/ad672570
The C-language FAQ: http://www.eskimo.com/~scs/C-faq/top.html
C-reference: http://www.dinkumware.com/manuals/reader.aspx?lib=c99
FAQ de f.c.l.c : http://www.isty-info.uvsq.fr/~rumeau/fclc/
Nov 14 '05 #5

"/* frank */" <__*******@despammed.com> wrote

If I have this array:

a[i]

the preprocessor translate it, into *(a+i)

a is translated as costant.

You can often get a preprocessor as a standalone program (cpp or something
similar). Why not run it on some C source and see what happens?
Nov 14 '05 #6
/* frank */ wrote:
My teacher said that array in C is managed by preprocessor.

Preprocesser replace all array occurences (i.e. int a[10] ) with
something that I don't understand/remember well.
Was it perhaps that a[10] is equivalent with 10[a], because
a compiler may transform a[10] into *(a + 10) and 10[a] in
*(10 + a)?

What's exactly happens with array during preprocessing/compiling stage?


The preprocessor is a kind of simple text processor with commands
that start with (and use) #. The preprocessing 'stage' is a
purely textual one; the meaning of C constructs like a[10] is
not know there. So only when 'a' would have been #defined, the
preprocessor will modify it textually (i.e., replace it with
what 'a' was #defined to be).

The compiler deals with the meaning of the (preprocessed C) code.
In differerent stages (using different internal representations),
the compiler transforms the C code into machine code. Often the
compiler generates assembly code, which is transformed into the
actual machine code by the assembler program.

Nov 14 '05 #7
"Case -" <no@no.no> wrote in message
news:40**********************@dreader2.news.tiscal i.nl...
What's exactly happens with array during preprocessing/compiling stage?


The preprocessor is a kind of simple text processor with commands
that start with (and use) #. The preprocessing 'stage' is a
purely textual one; the meaning of C constructs like a[10] is
not know there. So only when 'a' would have been #defined, the
preprocessor will modify it textually (i.e., replace it with
what 'a' was #defined to be).


The preprocessor operates on preprocessing tokens. It is not a text processor
except during initial tokenization. Otherwise, you're right. The preprocessor
does not transform "a[10]". In fact, even if 'a' was defined as a macro, there
is no way that macro expansion can extract the '10'.

Regards,
Paul Mensonides
Nov 14 '05 #8
/* frank */ wrote:
My teacher said that array in C is managed by preprocessor.

Preprocesser replace all array occurences (i.e. int a[10] ) with
something that I don't understand/remember well.

What's exactly happens with array during preprocessing/compiling stage?

Thanks in advance


Let's find out.

peter ) cat test.c
void function(void) {
int array[10];
array[1]=2;
array[5]=array[1];
}
peter ) cc -E test.c
# 1 "test.c"
#pragma GCC set_debug_pwd "/Users/peter"
# 1 "<built-in>"
# 1 "<command line>"
# 1 "test.c"
void function(void) {
int array[10];
array[1]=2;
array[5]=array[1];
}

Looks like nothing at all!

--
Pull out a splinter to reply.
Nov 14 '05 #9
Emmanuel Delahaye ha scritto:
Get a better teacher, and read your C-book about arrays. Do exercices.

K&R 2nd ed. writes that C compiler transform the expression
a[i] in *(a+i) so some kind of "conversion" happen, during
preprocessing stage?
Tks

Nov 14 '05 #10
/* frank */ wrote:
Emmanuel Delahaye ha scritto:
Get a better teacher, and read your C-book about arrays. Do exercices.


K&R 2nd ed. writes that C compiler transform the expression
a[i] in *(a+i) so some kind of "conversion" happen, during
preprocessing stage?


The compiler does many things other than in the preprocessing stage.
The compiler also emits some sort of code. Do you think the
preprocessor does that, too?
Nov 14 '05 #11
Paul Mensonides wrote:
"Case -" <no@no.no> wrote in message
news:40**********************@dreader2.news.tiscal i.nl...
What's exactly happens with array during preprocessing/compiling stage?


The preprocessor is a kind of simple text processor with commands
that start with (and use) #. The preprocessing 'stage' is a
purely textual one; the meaning of C constructs like a[10] is
not know there. So only when 'a' would have been #defined, the
preprocessor will modify it textually (i.e., replace it with
what 'a' was #defined to be).


The preprocessor operates on preprocessing tokens. It is not a text processor
except during initial tokenization.


Yes it is, CPP processes a text file (which happens to be C code),
it's as simple as that. You use 'initial tokenization' without
supplying the context (do you mean as part of C compilation, are
you talking about the internals of CPP, or ...). What do you mean?

Case

Nov 14 '05 #12
In <40***********************@news.xs4all.nl> Case <no@no.no> writes:
Paul Mensonides wrote:
"Case -" <no@no.no> wrote in message
news:40**********************@dreader2.news.tiscal i.nl...
What's exactly happens with array during preprocessing/compiling stage?

The preprocessor is a kind of simple text processor with commands
that start with (and use) #. The preprocessing 'stage' is a
purely textual one; the meaning of C constructs like a[10] is
not know there. So only when 'a' would have been #defined, the
preprocessor will modify it textually (i.e., replace it with
what 'a' was #defined to be).
The preprocessor operates on preprocessing tokens. It is not a text processor ^^^^^^^^^^^^^^^^^^^^ except during initial tokenization.


Yes it is, CPP processes a text file (which happens to be C code),
it's as simple as that.


Nope, it isn't. Try avoiding topic you don't have any clue about.
You use 'initial tokenization' without
supplying the context (do you mean as part of C compilation, are
you talking about the internals of CPP, or ...). What do you mean?


He means what he says: preprocessing tokens, as described by the C
language definition, which is the implicit context in this newsgroup.

If you still don't get it, consider the following example:

#if 0
That's all
#endif

and compare it with

/* That's all */

The first commenting method is valid only for correct C code, or, at least
sequences of valid C preprocessing tokens.

Dan
--
Dan Pop
DESY Zeuthen, RZ group
Email: Da*****@ifh.de
Nov 14 '05 #13
In <2k*************@uni-berlin.de> /* frank */ <__*******@despammed.com> writes:
My teacher said that array in C is managed by preprocessor.


Find another teacher. If this is not an option, learn C from K&R2: your
teacher doesn't know what he's talking about.

Dan
--
Dan Pop
DESY Zeuthen, RZ group
Email: Da*****@ifh.de
Nov 14 '05 #14
/* frank */ wrote:
Artie Gold ha scritto:
1) You misunderstood what your teacher said.
If I have this array:

a[i]


You mean, if you have this subscript expression. a[i] isn't
an array unless a is an array of arrays.
the preprocessor translate it, into *(a+i)
No, it doesn't. "Preprocessing" is a very specific stage in C
translation, and it doesn't do anything with expressions a[i]
(unless they're in a preprocessing expression).

a[i] *means* *(a+i), but that's nothing to do with the C
preprocessor.
a is translated as costant.


That statement is too vague to be wrong.

--
Chris "electric hedgehog" Dollin
C FAQs at: http://www.faqs.org/faqs/by-newsgrou...mp.lang.c.html
C welcome: http://www.angelfire.com/ms3/bchambl...me_to_clc.html
Nov 14 '05 #15
Dan Pop wrote:
In <40***********************@news.xs4all.nl> Case <no@no.no> writes:
Paul Mensonides wrote:
"Case -" <no@no.no> wrote in message
news:40**********************@dreader2.news.tis cali.nl...

>What's exactly happens with array during preprocessing/compiling stage?

The preprocessor is a kind of simple text processor with commands
that start with (and use) #. The preprocessing 'stage' is a
purely textual one; the meaning of C constructs like a[10] is
not know there. So only when 'a' would have been #defined, the
preprocessor will modify it textually (i.e., replace it with
what 'a' was #defined to be).

The preprocessor operates on preprocessing tokens. It is not a text processor ^^^^^^^^^^^^^^^^^^^^except during initial tokenization.
Yes it is, CPP processes a text file (which happens to be C code),
it's as simple as that.


Nope, it isn't. Try avoiding topic you don't have any clue about.


What matters to me is helping the OP better understand the
level at which CPP works. The term 'text processor', fits
well in this context of explaining the basics. I'm convinced
that the newby OP is not helped much with strict definitions
in terms of 'preprocessing tokens'.
<snip> consider the following example:

#if 0
That's all
#endif

and compare it with

/* That's all */

The first commenting method is valid only for correct C code, or, at least
sequences of valid C preprocessing tokens.


I admit that you reminded me that the first leads to an error,
and say thanks! However, this does not change my opinion that
the metaphoric 'kind of text processor', can help in understanding
the differences between preprocessing and compilation.

Case

Nov 14 '05 #16
/* frank */ <__*******@despammed.com> wrote:
Emmanuel Delahaye ha scritto:

Get a better teacher, and read your C-book about arrays. Do exercices.

K&R 2nd ed. writes that C compiler transform the expression
a[i] in *(a+i) so some kind of "conversion" happen, during
preprocessing stage?


What makes you think that this is done during the /preprocessing/ stage?
--
Alex Monjushko (mo*******@hotmail.com)
Nov 14 '05 #17
"Case -" <no@no.no> wrote in message
news:40**********************@dreader2.news.tiscal i.nl...
Dan Pop wrote:

The preprocessor operates on preprocessing tokens. It is not a text
processor ^^^^^^^^^^^^^^^^^^^^
except during initial tokenization.

Yes it is, CPP processes a text file (which happens to be C code),
it's as simple as that.

The preprocessor takes several steps (called phases of translation). The first
is the translation of external encoding, universal character names, and
trigraphs into some uniform internal format. The second phase deletes all
instances of backslash immediately followed by a newline. The third phase
tokenizes the result of the above--from that point on all processing is done
with preprocessing tokens--not text--until the seventh phase (where they are
converted to regular tokens). Macro expansion, specifically, doesn't happen
until the fourth phase.

Preprocessing tokens, BYW, are not a fancy way of saying "text" either. They
are distinct tokens--with a formal grammar and everything. The main differences
between "preprocessing tokens" and "tokens" is that 1) there are more of them,
and 2) the grammar for pp-numbers is much simpler. For example, # and ## are
preprocessing tokens, but they cannot be converted to a tokens in the
translation phase seven.
Nope, it isn't. Try avoiding topic you don't have any clue about.


What matters to me is helping the OP better understand the
level at which CPP works. The term 'text processor', fits
well in this context of explaining the basics. I'm convinced
that the newby OP is not helped much with strict definitions
in terms of 'preprocessing tokens'.


A term that is incorrect, like 'text preprocessor', is never better. All it
does is perpetuate the common myth that the preprocessor operates on text--which
it doesn't.
<snip> consider the following example:

#if 0
That's all
#endif

and compare it with

/* That's all */

The first commenting method is valid only for correct C code, or, at least
sequences of valid C preprocessing tokens.


I admit that you reminded me that the first leads to an error,
and say thanks! However, this does not change my opinion that
the metaphoric 'kind of text processor', can help in understanding
the differences between preprocessing and compilation.


In the metaphoric sense, the compiler of the underlying language is just as much
a text processor as the preprocessor. Despite what you're intentions may have
been and despite what your level of understanding of the preprocessor may be,
simplifying something as to make it incorrect (even if it is slightly) is
misleading and causes poor understanding to continue.

Readdressing the OP's original issue... The preprocessor does not transform
"A[b]" to "*(A + B)". Even though the underlying language parser might do so
internally--it doesn't have to. It only has to treat the two syntaxes
equivalently. E.g. the identity relation compares equal semantically.

Further, regardless of what macro definitions exist, the preprocessing token
sequence

A[b]

cannot be transformed via macro expansion to

*(A + B)

unless it is used as an argument in another macro invocation. E.g. it would
have to be something like this:

#define EMPTY()
#define DEFER(id) id EMPTY()

#define EAT(...)

#define A *(A + DEFER(EAT)(
#define B ) B) DEFER(EAT)(

#define M(...) __VA_ARGS__)

M( A[b] ) // *(A + B)

In other words, it isn't easy to even when you're trying to do it. (The above
requires a pretty conformant preprocessor, BTW--like gcc).

Regards,
Paul Mensonides
Nov 14 '05 #18
On Sun, 27 Jun 2004 16:31:47 +0200, /* frank */
<__*******@despammed.com> wrote:
My teacher said that array in C is managed by preprocessor.

Preprocesser replace all array occurences (i.e. int a[10] ) with
something that I don't understand/remember well.

What's exactly happens with array during preprocessing/compiling stage?
Thanks in advance


I have a question if
type a[10] = {0}
then
a[i] == *(a+i) == *(type*) ( (char*)a + i*sizeof(type))
or not?
Nov 14 '05 #19

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

Similar topics

16
by: Ekim | last post by:
hello, I'm allocating a byte-Array in C# with byte byteArray = new byte; Now I want to pass this byte-Array to a managed C++-function by reference, so that I'm able to change the content of the...
5
by: Cybertof | last post by:
Hello, Is it possible to convert a VB6 Array of Struct to a C# Array Of Struct ? The test context is a C# application calling a VB6 ActiveX DLL Function using UDT (User Defined Type) and...
2
by: Dick Swager | last post by:
The following code is from a solution with a C++ project and a C# project. The C++ project creates a managed array and the C# project tries to use it. But I am having a 'System.ValueType' to...
5
by: apm | last post by:
Any and all: Is there an efficient way to pass a large array from .NET to COM? Can references (or pointer) be passed from COM to NET and NET to COM without the object it refers to being copied?...
15
by: Geoff Cox | last post by:
Hello, Can I separately declare and initialize a string array? How and where would I do it in the code below? It was created using Visual C++ 2005 Express Beta 2 ... In C# I would have ...
12
by: Cmtk Software | last post by:
I'm trying to define an enum which will be used from unmanaged c++, C++/CLI managed c++ and from C#. I defined the following enum in a VS dll project set to be compiled with the /clr switch: ...
17
by: =?Utf-8?B?U2hhcm9u?= | last post by:
Hi Gurus, I need to transfer a jagged array of byte by reference to unmanaged function, The unmanaged code should changed the values of the array, and when the unmanaged function returns I need...
14
by: dan | last post by:
I would like to have the preprocessor automatically generate the number of array elements requested. Each element is zero. The elements get pasted into a larger array. The other elements may be...
5
by: =?Utf-8?B?QXlrdXQgRXJnaW4=?= | last post by:
Hi Willy, Thank you very much for your work. C++ code doesnot make any serialization. So at runtime C# code gives an serialization error at "msg_file_s sa = (msg_file_s) bf.Deserialize(ms);"...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...

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.