www.digitalmars.com         C & C++   DMDScript  

D - What am I missing?

reply "Scott Egan" <scotte tpg.com.aux> writes:
This compiles but, I get 'opCmp: Error: Access Violation'

Any thoughts?

class fred {
 char[] opAdd(fred a){ return "Hello"; }
}

int main(char[][] args)
{
 fred f = new fred();
 fred g = new fred();
 char[] s;

  s = g + f;

 printf("opCmp: %s", s ~ "\0" );
 return 0;
}
Apr 20 2004
next sibling parent reply J Anderson <REMOVEanderson badmama.com.au> writes:
Scott Egan wrote:

This compiles but, I get 'opCmp: Error: Access Violation'

Any thoughts?

class fred {
 char[] opAdd(fred a){ return "Hello"; }
}

int main(char[][] args)
{
 fred f = new fred();
 fred g = new fred();
 char[] s;

  s = g + f;

 printf("opCmp: %s", s ~ "\0" );
  

If of D arrays as a struct with a length at the front.
 return 0;
}


  

-- -Anderson: http://badmama.com.au/~anderson/
Apr 20 2004
next sibling parent reply "Scott Egan" <scotte tpg.com.aux> writes:
Sorry,  I'll try not to be so stupid in the future (but I can't promise
anything).

"J Anderson" <REMOVEanderson badmama.com.au> wrote in message
news:c63314$22ci$1 digitaldaemon.com...
 Scott Egan wrote:

This compiles but, I get 'opCmp: Error: Access Violation'

Any thoughts?

class fred {
 char[] opAdd(fred a){ return "Hello"; }
}

int main(char[][] args)
{
 fred f = new fred();
 fred g = new fred();
 char[] s;

  s = g + f;

 printf("opCmp: %s", s ~ "\0" );

If of D arrays as a struct with a length at the front.
 return 0;
}

-- -Anderson: http://badmama.com.au/~anderson/

Apr 20 2004
parent reply J Anderson <REMOVEanderson badmama.com.au> writes:
Scott Egan wrote:

Sorry,  I'll try not to be so stupid in the future (but I can't promise
anything).
  

read\understand the entire language specs before using it. I'm thinking about putting a extremely brief page on the wiki with "common errors/solutions" listed by the most commonly asked. And a link on the main page - "noobies click here". s ~ "\0" shows you almost had the right idea and coming from C++, it's an obvious mistake to make. I'm guessing that most people have done it at least once. -- -Anderson: http://badmama.com.au/~anderson/
Apr 21 2004
parent reply J C Calvarese <jcc7 cox.net> writes:
J Anderson wrote:

 Scott Egan wrote:
 
 Sorry,  I'll try not to be so stupid in the future (but I can't promise
 anything).
  

read\understand the entire language specs before using it. I'm thinking about putting a extremely brief page on the wiki with "common errors/solutions" listed by the most commonly asked.

Are you thinking of something like this? http://www.wikiservice.at/d/wiki.cgi?ErrorMessages
 And a link on the main page - "noobies click here".
 
 s ~ "\0"
 
 shows you almost had the right idea and coming from C++, it's an obvious 
 mistake to make. I'm guessing that most people have done it at least once.
 

-- Justin http://jcc_7.tripod.com/d/
Apr 21 2004
parent reply J Anderson <REMOVEanderson badmama.com.au> writes:
J C Calvarese wrote:

 J Anderson wrote:

 Scott Egan wrote:

 Sorry,  I'll try not to be so stupid in the future (but I can't promise
 anything).
  

read\understand the entire language specs before using it. I'm thinking about putting a extremely brief page on the wiki with "common errors/solutions" listed by the most commonly asked.

Are you thinking of something like this? http://www.wikiservice.at/d/wiki.cgi?ErrorMessages

Exactly but ... parhaps it could be ordered in a way that shows (what probably are) then most common first. Also have a big emphasize on the main page to get noobs there. -- -Anderson: http://badmama.com.au/~anderson/
Apr 21 2004
parent reply J C Calvarese <jcc7 cox.net> writes:
In article <c65nak$ev4$1 digitaldaemon.com>, J Anderson says...
J C Calvarese wrote:

 J Anderson wrote:

 Scott Egan wrote:

 Sorry,  I'll try not to be so stupid in the future (but I can't promise
 anything).
  

read\understand the entire language specs before using it. I'm thinking about putting a extremely brief page on the wiki with "common errors/solutions" listed by the most commonly asked.

Are you thinking of something like this? http://www.wikiservice.at/d/wiki.cgi?ErrorMessages

Exactly but ... parhaps it could be ordered in a way that shows (what probably are) then most common first. Also have a big emphasize on the main page to get noobs there.

Someone has helped us out with the ordering of the FAQ in the wiki in the last few days. I didn't realize how much it needed reordering. I'm really glad he made those changes. But the ordering of the error messages page makes sense to me. If you think it can be ordered better, I'd encourage you to reorder it. I think that's the idea of a wiki. (By the way, there's already a table of contents at the top of the page and most browsers have a Find command.) As far as encouraging people to get to the right page in the wiki, I don't know what else I can do. The wiki FAQ page has a blurb mentioning the error messages page now. Perhaps some of the FAQ questions aren't so frequently asked, but some effort has been made to organize them so that the important ones are found first. Justin
-- 
-Anderson: http://badmama.com.au/~anderson/

Apr 21 2004
parent reply J Anderson <REMOVEanderson badmama.com.au> writes:
J C Calvarese wrote:

As far as encouraging people to get to the right page in the wiki, I don't know
what else I can do. The wiki FAQ page has a blurb mentioning the error messages
page now. Perhaps some of the FAQ questions aren't so frequently asked, but some
effort has been made to organize them so that the important ones are found
first.

Justin
  

the front page a more and added a special message to D's biggest customers, C++ users. -- -Anderson: http://badmama.com.au/~anderson/
Apr 21 2004
parent J C Calvarese <jcc7 cox.net> writes:
J Anderson wrote:
 J C Calvarese wrote:
 
 As far as encouraging people to get to the right page in the wiki, I 
 don't know
 what else I can do. The wiki FAQ page has a blurb mentioning the error 
 messages
 page now. Perhaps some of the FAQ questions aren't so frequently 
 asked, but some
 effort has been made to organize them so that the important ones are 
 found
 first.

 Justin
  

the front page a more and added a special message to D's biggest customers, C++ users.

-- Justin http://jcc_7.tripod.com/d/
Apr 21 2004
prev sibling parent Ilya Minkov <minkov cs.tum.edu> writes:
J Anderson schrieb:

 Scott Egan wrote:
 
 This compiles but, I get 'opCmp: Error: Access Violation'

 Any thoughts?

 class fred {
 char[] opAdd(fred a){ return "Hello"; }
 }


Always returns a constant array literal.
 int main(char[][] args)
 {
 fred f = new fred();
 fred g = new fred();
 char[] s;

  s = g + f;


From here s points to constant array literal.
 printf("opCmp: %s", s ~ "\0" );
  

If of D arrays as a struct with a length at the front.

doesn't matter here, since pointer is the first in the function parameter parsing queue. Maybe the error happens at concatenation - but why? I think only assembly level debugging would help here. Besides, try splitting away concatenation onto a separate line. Make a new variable, don't use =~ else you might loose the bug. Sorry that i can't be more helpful at the moment. -eye
Apr 20 2004
prev sibling next sibling parent Andrew <Andrew_member pathlink.com> writes:
In article <c631su$20rf$1 digitaldaemon.com>, Scott Egan says...
This compiles but, I get 'opCmp: Error: Access Violation'

Any thoughts?

class fred {
 char[] opAdd(fred a){ return "Hello"; }
}

int main(char[][] args)
{
 fred f = new fred();
 fred g = new fred();
 char[] s;

  s = g + f;

 printf("opCmp: %s", s ~ "\0" );

Try %.*s
 return 0;
}

Apr 20 2004
prev sibling parent reply Ben Hinkle <bhinkle4 juno.com> writes:
 printf("opCmp: %s", s ~ "\0" );

This should either be (as other have said)
 printf("opCmp: %.*s", s ~ "\0" );
or
 printf("opCmp: %s", (char*)(s ~ "\0") );
Apr 20 2004
next sibling parent reply J Anderson <REMOVEanderson badmama.com.au> writes:
Ben Hinkle wrote:

 printf("opCmp: %s", s ~ "\0" );

This should either be (as other have said)
 printf("opCmp: %.*s", s ~ "\0" );
or
 printf("opCmp: %s", (char*)(s ~ "\0") );
  

questions to the wiki <g> ie it would search for two words, printf and %s, 97% of the time I reckon it would hit correct (sorry for sending a personal email :( ) -- -Anderson: http://badmama.com.au/~anderson/
Apr 20 2004
parent J C Calvarese <jcc7 cox.net> writes:
J Anderson wrote:
 Ben Hinkle wrote:
 
 printf("opCmp: %s", s ~ "\0" );

 This should either be (as other have said)
 printf("opCmp: %.*s", s ~ "\0" );
 or
 printf("opCmp: %s", (char*)(s ~ "\0") );
  

questions to the wiki <g> ie it would search for two words, printf and %s, 97% of the time I reckon it would hit correct (sorry for sending a personal email :( )

In the meantime, we could take turns manually directing them to: http://www.wikiservice.at/d/wiki.cgi?FaqRoadmap#RuntimeErrors or http://www.wikiservice.at/d/wiki.cgi?ErrorMessages -- Justin http://jcc_7.tripod.com/d/
Apr 20 2004
prev sibling parent reply Stewart Gordon <smjg_1998 yahoo.com> writes:
Ben Hinkle wrote:

 
  printf("opCmp: %s", s ~ "\0" );
 
 This should either be (as other have said)
  printf("opCmp: %.*s", s ~ "\0" );

Which makes the null terminator redundant.
  printf("opCmp: %s", (char*)(s ~ "\0") );

Or printf("opCmp: %s", toStringz(s) ); Stewart. -- My e-mail is valid but not my primary mailbox, aside from its being the unfortunate victim of intensive mail-bombing at the moment. Please keep replies on the 'group where everyone may benefit.
Apr 20 2004
parent Ben Hinkle <bhinkle4 juno.com> writes:
  printf("opCmp: %s", (char*)(s ~ "\0") );

Or printf("opCmp: %s", toStringz(s) );

oh yeah - it had been so long since I last toStringz'ed something I had forgotten all about it. I'll take that as a good sign :-) -Ben
Apr 20 2004