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 71397
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 10, 20262026-05-10T19:52:53+00:00 2026-05-10T19:52:53+00:00

I’m working on a code base in which we have several configurable types. One

  • 0

I’m working on a code base in which we have several configurable types. One of those types is 64 bit integer. When we compile for platforms that have no native 64 bit integer type, we simple represent 64 bit integers using a struct similar to

typedef struct {     unsigned int hi, lo; } int64; 

In order to make this type useful, all common operations are defined as functions such as

int64 int64_add(int64 x, int64 y); 

On platforms where a native 64 bit integer type is available, these operations simply look like

#define int64_add(x, y) ((x) + (y)) 

Anyway, on to the question. I am implementing some functionality regarding time and I want to represent my time using the 64 bit integer:

typedef int64 mytime; 

I also want all the common operations available to the int64 type to be available for my time type as well:

#define mytime_add(x, y) (mytime) int64_add((int64) (x), (int64) (y)) 

The problem with this is that the casts between the types mytime and int64 isn’t allowed in C (as far as I can tell anyhow). Is there any way to do this without having to reimplement all the add, sub, mul, div, etc functions for the mytime type?

One option is of course to never do the mytime typedef and simply use int64 everywhere I need to represent time. The problem with this is that I’m not sure if I always want to represent time as a 64 bit integer. Then there’s the issue of readable code as well… 🙂

  • 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. 2026-05-10T19:52:53+00:00Added an answer on May 10, 2026 at 7:52 pm

    Do you really need the cast? gcc is compiling the following example without any complains:

     typedef struct int64 int64;  struct int64 {     unsigned int hi, lo; };  typedef int64 mytime;  int64 add_int64(int64 a, int64 b) {     int64 c;     /* I know that is wrong */     c.hi = a.hi + b.hi;     c.lo = a.lo + b.lo;      return c; }  int main(void) {     mytime a = {1, 2};     mytime b = {3, 4};     mytime c;      c = add_int64(a, b);      return 0; } 
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 71k
  • Answers 71k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • added an answer The answer is yes, you surely can. You will need… May 11, 2026 at 1:12 pm
  • added an answer There are a lot of different network simulators dependant on… May 11, 2026 at 1:12 pm
  • added an answer This is what i done, i hope it fits for… May 11, 2026 at 1:12 pm

Related Questions

No related questions found

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.