Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

static[T] argument is not substituted properly in .emit pragma #4165

Open
endragor opened this issue May 15, 2016 · 3 comments
Open

static[T] argument is not substituted properly in .emit pragma #4165

endragor opened this issue May 15, 2016 · 3 comments

Comments

@endragor
Copy link
Contributor

Sample:

proc printStr(s: static[string]) =
  {.emit: "puts(`s`->data);" .}
printStr("hello static")

# sample.cpp:52:7: error: use of undeclared identifier 's0'
#         puts(s0->data);
#              ^
@Araq
Copy link
Member

Araq commented May 15, 2016

Well we could produce an error, but it's not supported. static parameters disappear at runtime.

@endragor
Copy link
Contributor Author

Would it be possible to emit a reference to the produced global variable in such case? Error is fine for me, there is a simple workaround:

{.emit:"""/*INCLUDESECTION*/
#include <stdio.h>
""".}
proc printStr(s: static[string]) =
  let sCopy = s
  {.emit: "puts(`sCopy`->data);" .}
printStr("hello static")

Although would be nice to get rid of copyString here. shallowCopy doesn't help.

@stale
Copy link

stale bot commented Aug 4, 2020

This issue has been automatically marked as stale because it has not had recent activity. If you think it is still a valid issue, write a comment below; otherwise it will be closed. Thank you for your contributions.

@stale stale bot added the stale Staled PR/issues; remove the label after fixing them label Aug 4, 2020
@stale stale bot removed the stale Staled PR/issues; remove the label after fixing them label Apr 1, 2021
@ringabout ringabout self-assigned this Apr 1, 2021
ringabout added a commit to ringabout/Nim that referenced this issue Apr 1, 2021
@ringabout ringabout removed their assignment Sep 22, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants