Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8430455
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T05:35:51+00:00 2026-06-10T05:35:51+00:00

When I try to define a constant in terms of another constant, both stored

  • 0

When I try to define a constant in terms of another constant, both stored in device constant memory, as in:

__device__ __constant__ float x=0.1;
__device__ __constant__ float y=2*x;

I get the error:

error: can’t generate code for non empty constructors or destructors on device

Any hints ?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T05:35:52+00:00Added an answer on June 10, 2026 at 5:35 am

    __constant__ is not the same as const. In particular, a __constant__ object can be modified from the host. So the compiler cannot apply compile time evaluation. A __constant__ object cannot be written from within the device code at runtime, so runtime initialization is also not possible. In addition, there is no init routine for the device that could perform such an initialization prior to the actual kernel code commencing execution. The error message produced by the compiler seems to allude to that last fact.

    You could use defined constants, for example:

    #define MAGIC_NUMBER_1  (0.1f)
    #define MAGIC_NUMBER_2  (2.0f * MAGIC_NUMBER_1)
    
    __constant__ float x = MAGIC_NUMBER_1;
    __constant__ float y = MAGIC_NUMBER_2;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I always get a build error when I try to define a C function
I get this error FB is not defined when i try to run this
As you can't have an array in a define or a class constant I
I have a constant defined as: #define BEGIN_IMPORT_STRING @Importing Hands!; But I get an
When I try to compile this code, I get a Case Expression Not Constant
When I try to use define('LANG', $this->uri->rsegment(2)); in constants.php , I got this error:
So I have this function: (define (try try-block catch-block finally-block) ; Implements try/catch/finally like
I have a header menu and try to define different CSS classes for each
I know how to do a global variable, but whenever I try to define
try: html = urlopen('http://glbse.com/api/asset/' + asset.name) except: print 'error while updating the price of

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.