J
James Kuyper
arnuld said:If the root is NULL, how am I supposed to use "root->next = p" ?
You don't; when you add the first element, you use root=p.
arnuld said:If the root is NULL, how am I supposed to use "root->next = p" ?
arnuld said:If the root is NULL, how am I supposed to use "root->next = p" ?
Richard Heathfield said:Keith Thompson said:
So would I. Is Larry around? Perhaps he could expand.
arnuld said:It means if I put an array inside a struct, then it will be passed as
a whole rather than a pointer ?
2nd, if I try to access that array (member of struct), e.g. lets say I
pass it to function, then it will still be passed as pointer.
arnuld said:It means if I put an array inside a struct, then it will be passed as
a *whole* rather than a pointer ?
2nd, if I try to access that array (member of struct), e.g. lets say I
pass it to function, then it will still be passed as pointer.
Richard Heathfield said:In C, try passing an array ***at all***. It can't be done, at least
not without tucking the array inside a struct or union.
BartC said:Your linked list logic seems a little strange (to me): your empty linked
list starts with a dummy node containing empty key/value pairs. Normally
you'd start with a NULL root (baseEelement) which subsequently points to the
first element which is added.
I have a question on this... well, it's perhaps a more general question.
If a compiler detects that it's safe to do so, is it free to optimize
out the struct copy and use a pointer instead? Do any compilers do
this?
luserXtrog said:When do you imagine it could be safe to do this?
Beej Jorgensen said:I have a question on this... well, it's perhaps a more general question.
If a compiler detects that it's safe to do so, is it free to optimize
out the struct copy and use a pointer instead? Do any compilers do
this?
Beej said:Well, the first thing that came to mind was any read-only situation:
void printbaz(struct foo f)
{
printf("%d\n", f.baz);
}
(gcc 4.3.3 copies the whole thing on the stack in this case. Maybe
circumstances in which such an optimization were easy to detect are too
rare to bother with. Or maybe I'm just thinking lamely right now
because I'm tired.)
Keith Thompson said:gcc's -Wwrite-strings option makes it non-conforming.
Does it? AIUI, it only swaps one consequence of undefined behaviour
(crashing upon writing to string literals) for another (allowing writing
to string literals).
What utter drivel. How can the code not work if it doesn't compile?CBFalconer said:James said:First you say it doesn't help,CBFalconer said:Ian Collins wrote:
arnuld wrote:
FAQ says that in both cases a[3] or p[3] , the value is same but
compiler gets there differently. Now I have seen my friend using
char *p = "world" notation (for using it as ab array of const
characters). Is it fine or dangerous. Myself, I do const char a[]
= "wordl" all the time, I never ever use char* p notation to point
to some literal but I want to know whether char *p is a good idea
or not.
No, it is not because attempting to modify a string literal gives
you undefined behaviour. Use const char *p.
No, that doesn't help.
and then you admit that it does help. It is precisely because of the... That 'const' only gives you the help of having the
compiler emit an error message (probably) when you try to write
into the string.
help you just mentioned, that he gave this advice.
It doesn't help make the code work. It does help alerting you to
the why.
CBFalconer said:Ian said:No, it is not because attempting to modify a string literal givesarnuld said:Here is FAQ 6.2:
char a[] = "hello";
car *p = "world";
FAQ says that in both cases a[3] or p[3] , the value is same but
compiler gets there differently. Now I have seen my friend using
char *p = "world" notation (for using it as ab array of const
characters). Is it fine or dangerous. Myself, I do const char a[]
= "wordl" all the time, I never ever use char* p notation to point
to some literal but I want to know whether char *p is a good idea
or not.
you undefined behaviour. Use const char *p.
No, that doesn't help. In either case you can't write into the
string. That 'const' only gives you the help of having the
compiler emit an error message (probably) when you try to write
into the string.
[/QUOTE]gcc's -Wwrite-strings option makes it non-conforming.
Does it? AIUI, it only swaps one consequence of undefined behaviour
(crashing upon writing to string literals) for another (allowing writing
to string literals).
Does it? AIUI, it only swaps one consequence of undefined behaviour
(crashing upon writing to string literals) for another (allowing writing
to string literals).
[ in a thread that mutated into whether C has pass-by-reference ](e-mail address removed) wrote:
No, Fortran passed everything (except arrays) by copy/restore. To pass
by reference, you had to decorate the formal paramter name with slashes:
SUBROUTINE SUB1(I, /J/) I passed by copy/restore, J by reference
Pass by copy/restore is similar to pass by value except that the final
value of the parameter is copied back into the argument when the
subroutine returns.
I think you must be remembering a dialect or even variant. I've never
seen syntax like that in any Fortran implementation, text, published
code, or standard back to 77.
66 was before I was playing close
attention, but the description of changes in 77 doesn't include any
such thing, and I can't imagine anything so fundamental going
unmentioned. Does the collective memory of c.l.f include this?
The only thing I know of that is even reasonably close is that
PL/I normally passes by-reference, but specifies that extra
*parentheses* around an argument mean it is first copied to a
temporary (and not copied back) giving the effect of by-value.
Want to reply to this thread or ask your own question?
You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.