Wrox Programmer Forums
C# Programming questions specific to the Microsoft C# language. See also the forum Beginning Visual C# to discuss that specific Wrox book and code.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the C# section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
Old December 2nd, 2005, 06:27 AM
Registered User
Join Date: Aug 2005
Posts: 9
Thanks: 0
Thanked 1 Time in 1 Post
Default C#

public struct SampleUnion
    [FieldOffset(0)] public uint dword;
    [FieldOffset(0)] public byte[] bytes;
    [FieldOffset(0)] public uint byte3;
    [FieldOffset(8)] public uint byte2;
    [FieldOffset(16)] public uint byte1;
    [FieldOffset(24)] public uint byte0;

uint S(SampleUnion x, uint y)

i am calling a function "S". Depending on the value y, the function should return the value of the expression "SBoxes[y][x.bytes##y])" (this expression is written in c)... suppose y=1, then SBoxes[1][x.bytes1]... where bytes1 is a member of the C# representation of C union. In the same way for y=2,3,.... i should be able to compute the expression by calling this function "S"...

In C, this can be done as..
uint S(SampleUnion x, uint y)

Here y is appended to bytes using "##". But i donot how i can do it in C#....Due to this i am not able to proceed further.So any kind of help is highly appreciated and will be waiting for any reply...


The Following User Says Thank You to virajithasarma For This Useful Post:

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.